如何处理 GDI 上的颜色丢失问题? 调整图像大小?
我使用 C#/GDI+ 调整图像大小,使用以下路由
bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
并以最高质量对其进行编码。
System.Drawing.Imaging.Encoder qualityEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameter myEncoderParameter = new EncoderParameter(qualityEncoder, 100L);
然而,我得到的图像有明显的颜色损失(我只使用 JPG 图像)。 质量完美,但颜色被洗掉了。 你知道发生了什么事吗?
预先非常感谢。
I am resizing images with C#/GDI+ using the following routing
bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
Graphics g = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
and encoding it with the highest quality.
System.Drawing.Imaging.Encoder qualityEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameter myEncoderParameter = new EncoderParameter(qualityEncoder, 100L);
However, the images that I get have significant loss of color (I am using JPG images only). The quality is perfect, but color is washed away. Do you have any idea what is goingf on?
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅如何禁用 .NET / GDI+ 的子采样?
问题是GDI+ 的 jpeg 编码器不允许禁用色度子采样,因此颜色信息以一半分辨率保存。 唯一的解决方法可能是使用不同的编码器,例如建议作为上述问题答案的 ImageMagick。
See How to disable subsampling with .NET / GDI+?
The problem is that GDI+'s jpeg encoder doesn't allow chroma subsampling to be disabled, so color information is saved at half resolution. The only workaround may be to use a different encoder, such as ImageMagick which was suggested as an answer to the above.