Click here to Skip to main content
15,356,641 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai good evening to all in my project customers upload their photographs how can i Compressed that photographs without lossing quality.
System.Drawing.Bitmap newBMP = new System.Drawing.Bitmap(originalBMP);
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
EncoderParameters myEncoderParameters = new EncoderParameters(1);
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 150L);
myEncoderParameters.Param[0] = myEncoderParameter;

private ImageCodecInfo GetEncoder(ImageFormat format)
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
            foreach (ImageCodecInfo codec in codecs)
                if (codec.FormatID == format.Guid)
                    return codec;
            return null;

i used the above coding but not the image size reduced and quality also reduced please help me 

                                  thanks in advance

                                      Meganathan M

1 solution

Yes. JPEG is a lossy compression technique - it always loses information, that is built in. You may get away with PNG, or TIFF which are lossless.
The best suggestion I can make is that you compress it to a ZIP file, and decompress it when you want to view it.
meganathanm 7-Apr-12 11:12am
Thank you for your quick reply.Can you give any example for this.
OriginalGriff 7-Apr-12 11:22am
Start here:
TIFF is not compression. It is a container which can be used for several compression method, including JPEG. The supported lostless compression methods include ZIP or LZW.

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900