![]() |
|
[.NET] [Solved] Vb.net GetPixel Wrong values? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] [Solved] Vb.net GetPixel Wrong values? (/showthread.php?tid=5655564) |
[Solved] Vb.net GetPixel Wrong values? - VmX5 - Jun 25, 2017 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) ![]() 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 * - +Haze - Jun 25, 2017 Why reinvent the wheel? Why not just encode the Image to a base64 string? * - VmX5 - Jun 25, 2017 (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 * - HFDone - Jun 26, 2017 which image format you using try to add 1 to r and b pixels and see if you still get wrong pixels * - Zilog80 - Jun 26, 2017 Point 1 I think you should change this: PHP Code for his one: Code rgbVal.A.ToStringbut, Code C h r (rgbVal.A)Point 2 I made a fast bench. Here the results: Code ...........Image Marshal.Copy() GetPixel()Code ............Image Marshal.Copy() GetPixel()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 ipbut, Marshal.Copy returs: Code Lorem ipand i guess this is the correct behaviour. Point 4 The source (you can check my SteganoNET here: https://github.com/kernelENREK/SteganoNET/blob/master/SteganoNET/Helpers/Stegano.vb) Spoiler (Click to View) Point 5 The Benchs: Spoiler (Click to View) Hope it helps! Edited https://stackoverflow.com/questions/41241831/wrong-rgb-values-in-getpixel-from-png-image Seems there is a bug on Image.FromFile() Just tested again like SO post said and GetPixel() return expected values * - VmX5 - Jun 26, 2017 (Jun 26, 2017 07:09 AM)Zilog80 Wrote: Edited Thanks for all the points! Your solution worked! :) Thanks! Would +rep again if could. I never knew about Marshal.Copy... :\ |