【发布时间】:2010-07-09 00:23:58
【问题描述】:
我在 .Net 2.0 中使用 C#,我想读入 PNG 图像文件并检查具有不透明像素的第一行和第一列。
我应该使用什么程序集和/或类?
【问题讨论】:
我在 .Net 2.0 中使用 C#,我想读入 PNG 图像文件并检查具有不透明像素的第一行和第一列。
我应该使用什么程序集和/或类?
【问题讨论】:
Bitmap System.Drawing.dll 程序集中的类:
Bitmap bitmap = new Bitmap(@"C:\image.png");
Color clr = bitmap.GetPixel(0, 0);
【讨论】:
好吧,Bitmap 类可以读取 PNG 文件并访问像素。它可以看到透明像素吗? PNG 支持透明度,而 BMP 不支持。但是,它仍然有效。
Bitmap bitmap = new Bitmap("icn_loading_animated3a.png");
pictureBox1.Image = bitmap;
Color pixel5by10 = bitmap.GetPixel(5, 10);
上面的代码读取了我的小图片,然后读取了一个透明像素。颜色类具有 RGBA 值,并且我读取的像素被识别为透明。
【讨论】:
当然,我已经搜索过并找到了 PngBitmapDecoder 类,但它似乎在 .Net 2.0 中不可用?
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapdecoder.aspx
上面的链接提到它在我似乎没有包含在 .Net 2.0 中的 PresentationCore 程序集中
【讨论】: