Click here to Skip to main content
14,422,431 members
Rate this:
Please Sign up or sign in to vote.
See more:
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;
}

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
Posted
Updated 17-May-18 1:06am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

remove the
img.Save("check1.jpg", jpegCodec, encoderParams);
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)?
   
Comments
XeeShaN AbbAs 26-Aug-11 17:18pm
   
I want to send the image through LAN so thats why i need to compress the image...
Member 13436267 1-Oct-17 3:32am
   
What if I want to display the image back in the picture box to save later or to view it..
Member 13975729 1-Mar-19 17:00pm
   
I have a similar issue right now. and i want to save the converted image to a folder. How do i do it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100