BMP为JPG在C#/ PNG [英] Bmp to jpg/png in C#

查看:303
本文介绍了BMP为JPG在C#/ PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为BMP图像转换为JPG / PNG不失在C#中的质量?使用图像类,我们可以转换BMP为JPG,但输出图像的质量非常差。我们能获得质量水平不如图像转换用photoshop最高质量为JPG?


解决方案

  VAR qualityEn codeR = EN coder.Quality;
VAR质量=(长)LT;所需的质量取代;
VAR比=新恩coderParameter(qualityEn codeR,质量);
变量codecParams =新恩coderParameters(1);
codecParams.Param [0] =比;
VAR JPEG codecInfo =<从图像codecInfo.GetImageEn codeRS的codeC的相关信息()的一个MIME类型=图像/ JPEG取代;
bmp.Save(文件名,JPEG codecInfo,codecParams); //保存为JPG

Is there any way to convert a bmp image to jpg/png without losing the quality in C#? Using Image class we can convert bmp to jpg but the quality of output image is very poor. Can we gain the quality level as good as an image converted to jpg using photoshop with highest quality?

解决方案

var qualityEncoder = Encoder.Quality;
var quality = (long)<desired quality>;
var ratio = new EncoderParameter(qualityEncoder, quality );
var codecParams = new EncoderParameters(1);
codecParams.Param[0] = ratio;
var jpegCodecInfo = <one of the codec infos from ImageCodecInfo.GetImageEncoders() with mime type = "image/jpeg">;
bmp.Save(fileName, jpegCodecInfo, codecParams); // Save to JPG

这篇关于BMP为JPG在C#/ PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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