为什么Bitmap(Image)构造函数会改变PixelFormat?

时间:2014-09-17 22:25:08

标签: c# duplicates clone system.drawing pixelformat

此代码:

System.Drawing.Bitmap bpp24 = new System.Drawing.Bitmap(3, 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Console.WriteLine("bpp24 pixel format is " + bpp24.PixelFormat.ToString());

System.Drawing.Image bpp24image = bpp24;
Console.WriteLine("bpp24image pixel format is " + bpp24image.PixelFormat.ToString());
System.Drawing.Bitmap duplicate = new System.Drawing.Bitmap(bpp24image);
Console.WriteLine("duplicate pixel format is " + duplicate.PixelFormat.ToString());

System.Drawing.Bitmap clone = (System.Drawing.Bitmap)bpp24.Clone();
Console.WriteLine("clone pixel format is " + clone.PixelFormat.ToString());

生成此输出:

  

bpp24像素格式为Format24bppRgb

     

bpp24image像素格式为Format24bppRgb

     

重复的像素格式是Format32bppArgb

     

克隆像素格式为Format24bppRgb

为什么复制的PixelFormat会发生变化?真正复制Bitmap的解决方法似乎是最后显示的对象级Clone方法(以及Bitmap级别的Clone方法,但需要一些额外的输入),但为什么不能使用更高级别的Bitmap(Image)构造函数用于复制位图?

另见Bitmap deep copy changing PixelFormatConverting Bitmap PixelFormats in C#

0 个答案:

没有答案