减小图像c#的大小

减小图像c#的大小

本文介绍了减小图像c#的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想减小和图像的大小

我谷歌它并找到一个解决方案



hi
I want reduce the size of and image
I google it and find a solution which is

void compress(Image img,string path){
    EncoderParameter qualityParam =
        new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 60);
    ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
    EncoderParameters encoderParams = new EncoderParameters(1);
    encoderParams.Param[0] = qualityParam;

    img.Save("check1.jpg", jpegCodec, encoderParams);
}
private static ImageCodecInfo GetEncoderInfo(string mimeType)
{
    // Get image codecs for all image formats
    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

    // Find the correct image codec
    for (int i = 0; i < codecs.Length; i++)
        if (codecs[i].MimeType == mimeType)
            return codecs[i];
    return null;
}



它减小了尺寸,但它将图像存储到硬盘我不想存储我想要使用的图像futhur .. ..

我怎么能这样做请帮助...... ??

谢谢


it reduce the size but it store the image to harddisk i dont want to store that image I want to use image futhur....
how could I do that please Help...??
Thanks

推荐答案

img.Save("check1.jpg", jpegCodec, encoderParams);

行并将Image实例 img 用于您想要的任何内容。我想你不知道如何使用 Image ,但为了获得更多的帮助,你需要告诉我们你想用它做什么。在UI(ASP.NET,Winforms,WPF)中显示它?

line and use the Image instance img to whatever you want. I guess you don't know how to use Image, but to get futher help on that front you'll need to tell us what you want to use it for. Display it in an UI (ASP.NET, Winforms, WPF)?


这篇关于减小图像c#的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:41