【问题标题】:Reading a PNG image file in .Net 2.0在 .Net 2.0 中读取 PNG 图像文件
【发布时间】:2010-07-09 00:23:58
【问题描述】:

我在 .Net 2.0 中使用 C#,我想读入 PNG 图像文件并检查具有不透明像素的第一行和第一列。

我应该使用什么程序集和/或类?

【问题讨论】:

    标签: c# .net


    【解决方案1】:

    Bitmap System.Drawing.dll 程序集中的类:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        【解决方案3】:

        当然,我已经搜索过并找到了 PngBitmapDecoder 类,但它似乎在 .Net 2.0 中不可用?

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

        上面的链接提到它在我似乎没有包含在 .Net 2.0 中的 PresentationCore 程序集中

        【讨论】:

        • 不,这是一个 WPF 程序集(.Net 3.0+)
        猜你喜欢
        • 1970-01-01
        • 2020-11-05
        • 2015-12-13
        • 1970-01-01
        • 1970-01-01
        • 2015-12-11
        • 2011-09-20
        • 2016-06-18
        • 1970-01-01
        相关资源
        最近更新 更多