所以我使用.NET 7
,因为System.Drawing.Imaging
可以(或似乎可以)使用以下代码将文件另存为webp
文件:
pictureBox1.Image = image; //image is a Bitmap
image.Save(folderpath, ImageFormat.Webp);
非常靠前,但保存的图像占716kb
,但其大小为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.
最新情况:
因此,我可以使用MSDN中的以下代码来降低PNG
的"质量":
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);
}
使用此方法的:
public static ImageCodecInfo GetEncoder(string mimetype)
{
return ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.MimeType == mimetype);
}
但我不明白为什么如果Save()
允许我另存为webp
文件,为什么ImageCodecInfo.GetImageEncoders()
中没有编码器来MIME TYPE WebP