在C#转换位图的PixelFormats [英] Converting Bitmap PixelFormats in C#

查看:1967
本文介绍了在C#转换位图的PixelFormats的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个位图转换 PixelFormat.Format32bppRgb PixelFormat.Format32bppArgb

I need to convert a Bitmap from PixelFormat.Format32bppRgb to PixelFormat.Format32bppArgb.

我希望利用Bitmap.Clone,但它似乎并不奏效。

I was hoping to use Bitmap.Clone, but it does not seem to be working.

Bitmap orig = new Bitmap("orig.bmp");
Bitmap clone = orig.Clone(new Rectangle(0,0,orig.Width,orig.Height), PixelFormat.Format24bppArgb);

如果我运行上面的code,然后检查clone.PixelFormat它设置为 PixelFormat.Format32bppRgb 。这是怎么回事/我怎么转换格式?

If I run the above code and then check clone.PixelFormat it is set to PixelFormat.Format32bppRgb. What is going on/how do I convert the format?

推荐答案

马虎,不寻常的GDI +。这种修复它:

Sloppy, not uncommon for GDI+. This fixes it:

        Bitmap orig = new Bitmap(@"c:\temp\24bpp.bmp");
        Bitmap clone = new Bitmap(orig.Width, orig.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
        using (Graphics gr = Graphics.FromImage(clone)) {
            gr.DrawImage(orig, new Rectangle(0, 0, clone.Width, clone.Height));
        }
        // Dispose orig as necessary..

这篇关于在C#转换位图的PixelFormats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆