Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

I’m using C# in .Net 2.0, and I want to read in a PNG image file and check for the first row and first column that has non-transparent pixels.

What assembly and/or class should I use?

Comments

Of course I googled already and found the PngBitmapDecoder class, but it doesn’t seem to be available in .Net 2.0?

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapdecoder.aspx

The above link mentions it’s in the PresentationCore assembly which I don’t seem to have included with .Net 2.0

Bitmap class from System.Drawing.dll assembly:

Bitmap bitmap = new Bitmap(@"C:\image.png");
Color clr = bitmap.GetPixel(0, 0);

Well, Bitmap class can read a PNG file and access pixels. Can it see transparent pixels? PNG supports transparency while BMP does not. But still, it works.

Bitmap bitmap = new Bitmap("icn_loading_animated3a.png");
pictureBox1.Image = bitmap;
Color pixel5by10 = bitmap.GetPixel(5, 10);

Code above read my little picture and then read a transparent pixel. Color class has RGBA values, and the pixel I read was in recognized as transparent.