Issue reading pixel data for JPEG

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
This is odd. Using VCS2008 I made a program that reads JPEG images (the palette is simple gray-scale from 0 to 255). It was working fine. I then installed VS2010 for VB and now when I read the pixel data, the intensities are suddenly multiples
of 17.
The code:
Bitmap rawImage = new Bitmap(aFile);<br/>
Rectangle rawRect = new Rectangle(0, 0, rawImage.Width, rawImage.Height);<br/>
BitmapData lockedImage = rawImage.LockBits(<br/>
rawRect,<br/>
System.Drawing.Imaging.ImageLockMode.ReadOnly,<br/>
System.Drawing.Imaging.PixelFormat.Format8bppIndexed);<br/>
byte[] rawData = new byte[rawImage.Width * rawImage.Height];<br/>
System.Runtime.InteropServices.Marshal.Copy(lockedImage.Scan0, rawData, 0, rawData.Length);
A sample image is at http://www.lpi.usra.edu/resources/apollo/images/print/AS15/M/0070.jpg.
If you do a histogram of the image using some tool, you get a nice distribution of pixel intensities (I use IrfanView and ImageJ). I wrote my own little histogram within my program right after the code snippet above, and it did NOT calculate a good
histogram distribution. The only pixel intensities it saw were values of 0, 17, 34, 51 and so on... multiples of 17. When I then simply looked at the byte values in my rawData array, I saw the same thing -- all values were multiples of 17.
The code was working a week or so ago, where the values in rawData were well distributed. The only thing I can think of that changed was installing Visual Basic Express 2010. The code above has not changed.
The REALLY odd thing is if I use MS Paint to convert the JPEG to BMP and do a histogram on it, then IrfanView and ImageJ ALSO see the odd multiple-of-17 distribution on the BMP. Then if I use IrfanView or ImageJ to convert the JPEG to a BMP, their
BMPs show the same nice distribution... and so does my histogram calculation when my code looks at their BMPs. But when I have my code read the BMP that Paint made, I get the odd multiple-of-17 thing.
Its as if something deep in the bowels of Microsoft Windows 7 got corrupted -- some sort of JPEG decoder.
I am running Win 7 on a 64-bit Vaio.

View the full article
 
Back
Top