【发布时间】:2010-01-06 21:32:05
【问题描述】:
我需要将位图从PixelFormat.Format32bppRgb 转换为PixelFormat.Format32bppArgb。
我希望使用 Bitmap.Clone,但它似乎不起作用。
Bitmap orig = new Bitmap("orig.bmp");
Bitmap clone = orig.Clone(new Rectangle(0,0,orig.Width,orig.Height), PixelFormat.Format24bppArgb);
如果我运行上面的代码然后检查 clone.PixelFormat 它被设置为PixelFormat.Format32bppRgb。发生了什么/如何转换格式?
【问题讨论】:
-
这种情况只发生在 XP 上吗?我在 XP 上发现了这个问题,但它似乎在 Windows 7 上运行良好。Hans 的解决方案为我解决了这个问题。
-
这很有趣。我有一个在 XP 上运行良好但在 Windows 7 上出现此错误的解决方案...
-
我可以确认只有 XP 受到影响。
-
您也应该注意不是 XP 的系统。我没有测试过这个特殊的代码,但是在 Windows 7 上比较两个图像时在像素级别上工作时,我遇到了由这个错误/功能引起的类似问题。 Dan7 准确地解释了正在发生的事情以及修复它的更一般的方法。