操纵System.Drawing.Image并使用相同的ImageFormat保存

比方说,我想要一种方法,通过弄乱图像的像素值来对图像进行一些处理,然后返回图像,否则该图像就是“相同”(等于PixelFormatRawFormat,{{ 1}}等。

VerticalResolution

我一直很难做到这一点,因为要操纵其像素我想使用public static Image DoSomeManipulation(this Image source) { // ... } ,但是我找不到找到创建具有相同{{1 }}。

我尝试过:

Bitmap

Bitmap

ImageFormat

在我测试我的1000个随机文件(PNG,JPG等)时,它们每个都工作了一段时间,但都失败了

var target = new Bitmap(source);

一些 ,我不知道为什么。

有没有不涉及其中一种的解决方案

  • var temp = new Bitmap(source) var target = temp.Clone(new Rectangle(0,temp.Width,temp.Height),source.PixelFormat); 进行序列化和反序列化(是的,我见过this
  • 如果var temp = new Bitmap(source) var target = temp.Clone(new Rectangle(0,temp.PixelFormat); 是本地文件,请在Assert.AreEqual(target.ImageFormat,source.ImageFormat); 存储或类似的存储中创建副本

??

jinruien0219 回答:操纵System.Drawing.Image并使用相同的ImageFormat保存

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3105421.html

大家都在问