在 .Net 2.0 中读取 PNG 图像文件

15

我正在使用 .Net 2.0 中的 C#,想要读取一个 PNG 图像文件并检查第一行和第一列是否存在非透明像素。

我应该使用哪个程序集和/或类?

3个回答

23
来自 System.Drawing.dll 程序集的 Bitmap 类:

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

1

不,这是一个 WPF 组件 (.Net 3.0+)。 - Lucas

1

Bitmap类可以读取PNG文件并访问像素。它能看到透明像素吗?PNG支持透明度,而BMP则不支持。但是,它仍然能工作。

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

上面的代码读取了我的小图片,然后读取了一个透明像素。Color类具有RGBA值,而我读取的像素被识别为透明。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接