不保存就降低JPEG图像质量 [英] Reducing JPEG image quality without saving

查看:85
本文介绍了不保存就降低JPEG图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以最快的方式以编程方式降低图像质量.现在,我能够从byte[]读取图像,然后作为MemoryStream读取到Bitmap,并通过Drawing.Imaging.Encoder.Quality更改保存到所需20L时的质量.

I am trying to programatically reduce the quality of an image in the fastest way possible. Right now, I am able to read image from byte[], then as a MemoryStream read it to Bitmap and via Drawing.Imaging.Encoder.Quality change its quality when saving to desired 20L.

我想知道是否有一种方法可以在不保存整个图像的情况下进行操作.是否可以仅更改位图bmp1或创建会降低图像质量的新位图?

I would like to know if there is a way to do this without saving the whole image. Is there way to just change the bitmap bmp1, or create a new bitmap that would have the image quality reduced?

byte[] imageBytes = convertImageToByteArray(bmpScreenshot);
MemoryStream mem = new MemoryStream(imageBytes);
using (Bitmap bmp1 = (Bitmap)Image.FromStream(mem))
{

     ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
     ImageCodecInfo jgpEncoder = codecs[1];

     System.Drawing.Imaging.Encoder myEncoder =
     System.Drawing.Imaging.Encoder.Quality;

     myEncoderParameter = new EncoderParameter(myEncoder, 20L);
     myEncoderParameters.Param[0] = myEncoderParameter;
     bmp1.Save(@"C:\TestPhotoQuality20L.jpg", jgpEncoder, myEncoderParameters);
}

推荐答案

而不是将bmp1保存到文件中.您可以将其保存到另一个MemoryStream.然后,您可以从此MemoryStream加载新的位图.

Instead of saving bmp1 to a file. You can save it to another MemoryStream. Then you could load a new bitmap from this MemoryStream.

这篇关于不保存就降低JPEG图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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