namespace bmp转jpg
{
internal class Program
{
static void Main(string[] args)
{
Bitmap image = new Bitmap("D:\\桌面\\Image.bmp");
//转成jpg的准备工作
var myEncoderParameters = new EncoderParameters(1);
var myEncoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 85L);
myEncoderParameters.Param[0] = myEncoderParameter;
ImageCodecInfo jpsEncodeer = GetEncoder(ImageFormat.Jpeg);
//设置保存图片的路径并保存
var path = "Shapes085.jpg";
image.Save(path, jpsEncodeer, myEncoderParameters);
//释放资源
image.Dispose();
myEncoderParameters.Dispose();
}
public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
return codec;
}
return null;
}
}
}
C# .bmp转jpg
最新推荐文章于 2024-07-12 17:40:41 发布