为System.Drawing.Image保存()产生不一致的文件大小 [英] System.Drawing.Image Save() producing inconsistent file sizes

查看:249
本文介绍了为System.Drawing.Image保存()产生不一致的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在转换TIFF格式为PDF,我注意到一些PDF文件被损坏。经过一番研究,它出现的问题是在为System.Drawing.Image类。为了测试,而不是转换为PDF此,我有计划只读取图像文件并重新保存它们。一些新保存的文件有不同的程序运行之间不一致的文件大小。的基本步骤是:

While converting TIFFs to PDFs, I noticed some of the PDFs were corrupted. After some research, it appears the problem is in the System.Drawing.Image class. To test this, instead of converting to PDFs, I had the program just read in the image files and re-save them. Some of the newly saved files have inconsistent file sizes between different runs of the program. The basic steps are:

  1. 在我读了TIFF图像到一个字节数组。
  2. 我用的是System.Drawing.Image.FromStream()方法创建的字节数组中的图像对象。
  3. 在我随后致电System.Drawing.Image.Save(流)的方法将图像保存到一个新的数据流。
  4. 在我然后检查stream.ToArray()方法的长度。

同样的输入文件产生连续的程序执行之间不同的输出长度。输出长度几百个字节变化。此外,所得到的输出长度大于输入长度的两倍,但我认为这是由于玉米pression,或缺乏。我在Windows 7上运行这32位在.NET 4中。

The same input file results in a different output length between successive program executions. The output length varies by a couple hundred bytes. In addition, the resulting output length is more than twice the size of the input length, but I assume this is due to compression, or lack thereof. I am running this on windows 7 32-bit with .net 4.

为什么会输出长度变化这样吗?

Why might the output length vary like this?

更新:

审查这一连接问题(<经过href="https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7)而这个MSDN页面上的社会评论(的http:// msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx ),它出现的问题与在Windows 7操作系统级的错误任何人都可以证实这一点,或提供解决方法吗?

After reviewing this connect issue (https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7) and the community comment on this MSDN page (http://msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx), it appears the issue is related to an operating system level bug in Windows 7. Can anyone confirm this or offer a workaround?

推荐答案

正如我在更新,审阅了连接问题(<一后href="https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7)而这个MSDN页面上的社会评论(的http:// msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx ),它出现的问题在Windows 7相关的操作系统级的错误。

As stated in my update, after reviewing this connect issue (https://connect.microsoft.com/VisualStudio/feedback/details/584681/system-drawing-image-flags-has-different-value-in-vista-and-windows-7) and the community comment on this MSDN page (http://msdn.microsoft.com/en-us/library/system.drawing.image.save.aspx), it appears the issue is related to an operating system level bug in Windows 7.

此外,当使用Windows XP读取图像,图像对象上的标志属性设置为77888. Win7上,它被设置为77840.审查MSDN文档的标志性(的 http://msdn.microsoft.com/en-us/library/system .drawing.image.flags.aspx 的),所不同的是WinXP的标记的图像作为灰度图像(这是矿),但是Win7的标记它作为一个RGB图像。这似乎是问题的症状,但我不知道足够的图像格式和色彩空间与权力谈到这个。

In addition, when the images are read in Windows XP, the flags property on the image object is set to 77888. On Win7, it is set to 77840. After reviewing the MSDN documentation for the flags property (http://msdn.microsoft.com/en-us/library/system.drawing.image.flags.aspx), the difference is that WinXP flagged the image as a grayscale image (which mine are), but Win7 flagged it as an RGB image. This appears to be a symptom of the problem, but I don't know enough about image formats and color spaces to speak with authority on this.

这篇关于为System.Drawing.Image保存()产生不一致的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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