C# resize, resave .tif as .jpg gives a blue tint to the new image
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开发者_StackOverflow社区
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!
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:
- Create a plain image with a single colour.
- Convert it to jpeg.
- Then check in a photo package if the hue has actually changed or if it is your perception.
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.
精彩评论