我正在使用 .Net 2.0 中的 C#,想要读取一个 PNG 图像文件并检查第一行和第一列是否存在非透明像素。
我应该使用哪个程序集和/或类?
当然我已经谷歌过了,找到了PngBitmapDecoder类,但它似乎在.Net 2.0中不可用?
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapdecoder.aspx
上面的链接提到它在PresentationCore程序集中,但我好像没有将其包含在.Net 2.0中。
Bitmap类可以读取PNG文件并访问像素。它能看到透明像素吗?PNG支持透明度,而BMP则不支持。但是,它仍然能工作。
Bitmap bitmap = new Bitmap("icn_loading_animated3a.png");
pictureBox1.Image = bitmap;
Color pixel5by10 = bitmap.GetPixel(5, 10);
上面的代码读取了我的小图片,然后读取了一个透明像素。Color类具有RGBA值,而我读取的像素被识别为透明。