Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Solved] Vb.net GetPixel Wrong values?

So I've drawn pixels onto a bitmap using Bitmap.SetPixel() and I've checked the saved file using a photo editor to check if the correct ARGB values were drawn. But now the issue is when I try to read it some values are 1 or 2 off.

This is the function I wrote to translate image to text



These are the 2 pixels, they contain 4 chars each. (Enlarged ofc)
[Image: 635d1c439418b33a8da87132cdb9b464.png]

First Pixel : [76, 111, 114, 101]
Second Pixel : [109, 32, 105, 112]

But .Net would read:

First Pixel : [76, 110, 114, 100]
Second Pixel : [109, 32, 105, 112]

So is there something off with my code, or is there some other function I should use? or...? Yeah.

~VmX5
Why reinvent the wheel? Why not just encode the Image to a base64 string?
(Jun 25, 2017 05:34 PM)+Haze Wrote:  Why reinvent the wheel? Why not just encode the Image to a base64 string?

So in my previous versions of "Imext" I utilized the RGB values in a pixel but now I'm also trying to implement the Alpha value. So I need to be able to translate text into an image and back. But yea I got really stumped on this part :\

+Wheels are boring
which image format you using
try to add 1 to r and b pixels and see if you still get wrong pixels
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Point 1

I think you should change this:

PHP Code

<?php 
For Each rgbVal In rgbList
       returnString 
&= rgbVal.A.ToString & rgbVal.R.ToString & rgbVal.G.ToString & rgbVal.B.ToString
    Next 

for his one:



Code
rgbVal.A.ToString
will return "65" for alpha value = 65

but,
Code
C h r (rgbVal.A)
will retun "A" for alpha value = 65

Point 2

I made a fast bench. Here the results:

Code
...........Image      Marshal.Copy()    GetPixel()
i7-6700     2x1        2 ms              2 ms
i7-6700     200x100    1 ms              216 ms
i7-6700     400x300    6 ms              19352 ms

Code
............Image      Marshal.Copy()    GetPixel()
i5-M520     2x1        4 ms              3 ms
i5-M520     200x100    4 ms              687 ms
i5-M520     400x300    18 ms             38547 ms

The times measured how much time (in milliseconds) takes a a "TranslateImageToText()" function to complete.
As you can see, Marshal.Copy literally out-performs GetPixel() function.

I tried a 800x600 pixel image on my i7. Marshal.Copy() takes 29 ms, but GetPixel() takes ages: 427,287 ms, this is 7 minutes (and with a lot Garbage Collector memory allocations)

Point 3

You are right. I tried 2x1 pixel image with alpha + RGB values you posted. GetPixel() returns:
Code
Lnrdm ip

but, Marshal.Copy returs:
Code
Lorem ip

and i guess this is the correct behaviour.

Point 4

The source (you can check my SteganoNET here: https://github.com/kernelENREK/SteganoNE...Stegano.vb)

Spoiler (Click to View)

Point 5

The Benchs:

Spoiler (Click to View)

Hope it helps!

Edited
https://stackoverflow.com/questions/4124...-png-image

Seems there is a bug on Image.FromFile()
Just tested again like SO post said and GetPixel() return expected values
(Jun 26, 2017 07:09 AM)Zilog80 Wrote:  Edited
https://stackoverflow.com/questions/4124...-png-image

Seems there is a bug on Image.FromFile()
Just tested again like SO post said and GetPixel() return expected values

Thanks for all the points! Your solution worked! :) Thanks! Would +rep again if could.

I never knew about Marshal.Copy... :\


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Source] by HackersNov 19, 2024 01:51 PM 15 689 Nov 19, 2024 01:51 PM
Last Post: Hackers
[Python] by simmerDec 3, 2021 06:39 AM 4 177 Dec 3, 2021 06:39 AM
Last Post: simmer
[.NET] by PoppiecornNov 6, 2021 08:49 AM 1 174 Nov 6, 2021 08:49 AM
Last Post: donthakyou