C# 调整大小,将 .tif 重新保存为 .jpg 为新图像提供蓝色色调
我正在构建一个批处理器来将 .tif 图像目录保存为 .jpg。处理工作正常。然而,渲染的 jpg 带有蓝色调。它们不是“蓝色”,尽管它们具有较冷的色调,蓝色色调。原版的颜色更明亮、更温暖。这就是我创建调整大小的 jpeg 的方式:
Bitmap bitmap = new Bitmap(image.Image, size);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
graphics.DrawImage(image.Image, 0, 0, size.Width, size.Height);
// Get EncoderInfo("image/jpeg") gets the jpeg Codec by mime type
bitmap.Save(path, GetEncoderInfo("image/jpeg"), EncoderParameters);
原始 tif 图像的大小为 7MB - 与渲染的 jpeg 相比很大。也许这与此有关。没有把握。
我在谷歌上一无所获。有谁有这方面的经验或对下一步尝试什么有任何建议吗?谢谢!
I'm building a batch processor to save a directory of .tif images as .jpgs. The processing is working fine. However, the rendered jpgs have a blue-ish tint to them. They aren't "blue", as much as they have a cooler hue, a blue hue. The originals are much brighter and warmer in color. This is how I am creating the resized jpeg:
Bitmap bitmap = new Bitmap(image.Image, size);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
graphics.DrawImage(image.Image, 0, 0, size.Width, size.Height);
// Get EncoderInfo("image/jpeg") gets the jpeg Codec by mime type
bitmap.Save(path, GetEncoderInfo("image/jpeg"), EncoderParameters);
The original tif images are 7MB is size - large in comparison to the rendered jpegs. Perhaps that has something to do with it. Not sure.
I've come up empty on the Googles. Does anyone have any experience with this or any advice on what to try next? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
原始文件可能具有颜色配置文件。在这种情况下,您还需要将该信息复制到新文件中。我不知道如何使用 .NET 的成像类来做到这一点。
It could be that the original files have a color profile. In that case, you need to copy that information into the new file as well. I don't know how to do that with .NET's imaging classes.
我首先建议一个测试:
I would first suggest a test:
从 MSDN 文档来看,您似乎可以更简单地执行此操作(假设 image.Image 是实际的 System.Drawing.Image 实例)
:
image.Image.Save(路径,System.Drawing.ImageFormat.Jpeg)
这可能会有所帮助 - 看起来您正在将 TIF 转换为位图,然后才转换为 JPG。
From the MSDN documentation, it looks like you can be doing this somewhat simpler (assuming image.Image is an actual System.Drawing.Image instance):
image.Image.Save(path, System.Drawing.ImageFormat.Jpeg)
That might help - it looks like you're taking your TIF, converting to a bitmap, and only then converting to a JPG.