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
.
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);
}