位图深拷贝改变的PixelFormat [英] Bitmap deep copy changing PixelFormat

查看:219
本文介绍了位图深拷贝改变的PixelFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bitmap img = new Bitmap("C:\\temp\\images\\file.jpg");

img.PixelFormat是Format24bppRgb

img.PixelFormat is Format24bppRgb

当我做深拷贝

Bitmap img2 = new Bitmap(img);

img.PixelFormat改变为Format32bppArgb

img.PixelFormat is changed to Format32bppArgb

为什么它会改变像素格式?如何使深拷贝的对象,如果它不会使深层副本?

why does it change pixel format? and how to make deep copy for the object if it doesn't make deep copy?

推荐答案

您可以复制这样的位图,这将创建一个深度复制:

You can clone the bitmap like this, which will create a deep copy:

Bitmap img = new Bitmap("C:\\temp\\images\\file.jpg");

// Clone the bitmap.
Rectangle cloneRect = new Rectangle(0, 0, img.Width, img.Height);
System.Drawing.Imaging.PixelFormat format =
    img.PixelFormat;
Bitmap img2 = img.Clone(cloneRect, format);

这篇关于位图深拷贝改变的PixelFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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