Click here to Skip to main content
15,308,404 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;


C#
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

                                         By
                                      Meganathan M
Posted

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.
   
Comments
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: http://www.codeproject.com/Articles/37887/C-Zip-Files-and-or-Folders
   
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.
--SA

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