Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this questionI want to be able to take a low-quality image of the screen. I can take a bitmap picture, but no matter wha开发者_StackOverflow中文版t I do I can't lower its quality.
Image bmp1 = GetScreenImage ();
// Save the image as a GIF.
bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);
Msdn for more.
I would try converting the image to a compressed jpeg. The nice thing about jpegs is that you can set how high the quality should be (i.e. how much you want it compressed):
Note: quality should be between 1 and 100 (100 being the largest size/highest quality and 1 being the smallest size/lowest quality.
public void save(string filename, Bitmap img, int quality)
{
// quality encoding
EncoderParameter qualParam = new EncoderParameter(Encoder.Quality, quality);
// code for jpeg image type
ImageCodecInfo jpegCodec = FindEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = qualParam;
img.Save(filename, jpegCodec, encoderParams);
}
private ImageCodecInfo FindEncoderInfo(string mimeType)
{
// search through all codecs for all formats
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
for (int i = 0; i < codecs.Length; i++)
{
if (codecs[i].MimeType == mimeType)
{
return codecs[i];
}
}
return null;
}
精彩评论