C#.net图像重新缩放颜色问题

C#.net图像重新缩放颜色问题,c#,bitmap,scaling,C#,Bitmap,Scaling,我正在尝试用c#net动态地重新缩放图像。看起来一切正常,但仔细检查,颜色看起来不太合适 代码看起来非常直接,并且可以重新缩放,但是为什么原始图像比缩放后的图像显示的颜色更粉红 using (Bitmap origBitmap = new Bitmap("my_picture.jpg")) { using (Bitmap outputImage = new Bitmap(1024, 768, origBitmap.PixelFormat)) { outputIma

我正在尝试用c#net动态地重新缩放图像。看起来一切正常,但仔细检查,颜色看起来不太合适

代码看起来非常直接,并且可以重新缩放,但是为什么原始图像比缩放后的图像显示的颜色更粉红

using (Bitmap origBitmap = new Bitmap("my_picture.jpg"))
{
    using (Bitmap outputImage = new Bitmap(1024, 768, origBitmap.PixelFormat))
    {
        outputImage.SetResolution(origBitmap.HorizontalResolution, origBitmap.VerticalResolution);
        using (Graphics g = Graphics.FromImage(outputImage))
        {
            g.Clear(Color.Black);
            g.CompositingMode = CompositingMode.SourceCopy;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(
                origBitmap,
                new Rectangle(0, 0, 1024, 768),
                new Rectangle(0, 0, origBitmap.Width, origBitmap.Height),
                GraphicsUnit.Pixel
            );

            context.Response.ContentType = "image/jpeg";
            outputImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        }
    }
}
附加您可以看到在颜色上的差异。希望我错过了一些简单的事情


看来我回答了我自己的问题

using (Bitmap origBitmap = (Bitmap) Bitmap.FromFile("my_file.jpg", true))
{ … }

“true”参数用于“UseMbeddedColorManagement”。将其设置为true可以解决问题…

这不是重新缩放图像的好方法。你是放大还是缩小?同时,请参阅和。示例代码和一些提示。出于好奇,为什么这样做不好?我之所以使用ImageFormat,是因为它有一个RotateFlip函数,我需要能够将图像翻转到不同的方向。很抱歉,在询问为什么这是一个糟糕的方法之前,我应该先阅读您的链接。:)好的,今晚我将看一看这些例子,看看它是否有区别。谢谢你的快速回复<代码>图像格式也可能有其作用。GDI+针对PNG渲染进行了优化。这是它的默认格式。
.Jpg
格式(缺乏对有损压缩的有效控制)确实不是。这并不意味着图像颜色被滥用。但在重新采样时,质量可能会令人失望。应用像
RotateFlip
这样的矩阵变换不会影响输出质量。当图像实际保存并存储此信息时,这将起作用。无论如何,尝试使用嵌入的信息是一种很好的做法。如果您愿意,我可以发布和编码器质量设置,这样您就可以控制图像的最终DPI和整体图像质量设置(作为参考,然后您可以勾选您的答案)。