tags:

views:

1238

answers:

4

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?

A: 

You might need to manipulate the FileStream result: you also have this options :

// Open a Stream and decode a PNG image
Stream imageStreamSource = new FileStream("smiley.png", FileMode.Open, FileAccess.Read, FileShare.Read);
PngBitmapDecoder decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];

// Draw the Image
Image myImage = new Image();
myImage.Source = bitmapSource;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(20);
Alexandre Brisebois
He asked for C# 2.0, PngBitmapDecoder is a WPF class (.Net 3.0+)
Lucas
A: 

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

Roy Tang
No, it's a WPF assembly (.Net 3.0+)
Lucas
+7  A: 

Bitmap class from System.Drawing.dll assembly:

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

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.

ArekBulski