So I'm working with .NET 7
since System.Drawing.Imaging
can (or seems to be) save a file as webp
file with the following code:
pictureBox1.Image = image; //image is a Bitmap
image.Save(folderpath, ImageFormat.Webp);
Pretty forward, but the image saved occupies 716kb
but its size is 640
x480
How can I reduce the file size?
I found a lot of answers about reduce the image size, but is not my case, already reduced, and I'm wonder why a webp file will be so big, because the quality also is very poor (webcam image).
Using the PNG
format ocuppies the same space on disk.
UPDATE:
So I could reduce "the quality" of PNG
with the following code from MSDN:
if (capture.IsOpened())
{
capture.Read(frame);
image = BitmapConverter.ToBitmap(frame);
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
pictureBox1.Image = image;
ImageCodecInfo myImageCodecInfo;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoder("image/webp");
myEncoderParameters = new EncoderParameters(1);
myEncoder = System.Drawing.Imaging.Encoder.Quality;
// Save the bitmap as a JPEG file with quality level 25.
myEncoderParameter = new EncoderParameter(myEncoder, 25L);
myEncoderParameters.Param[0] = myEncoderParameter;
// and now save it to the file
image.Save(filename, myImageCodecInfo, myEncoderParameters);
}
that uses this method:
public static ImageCodecInfo GetEncoder(string mimetype)
{
return ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.MimeType == mimetype);
}
but I can't understand why if Save()
allows me to save as webp
file, there is no encoder to mimetype webp in ImageCodecInfo.GetImageEncoders()