How can i compress my images like a image is in big size then how can i compress its size an all
waiting for easy method.
Compress images
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 29, 2009, 6:31 PM EST
Here is Code to Compress the Image
------------------------------------
if my answer helps you then check do you like this answer check box please :)
string ImagePath = @"\\My Documents\\sampleimage.jpg";
string newImagePath = @"\\My Documents\\CompressedImage.jpg";
Bitmap ImgTemp;
ImgTemp = new Bitmap(ImagePath);
SaveJPGWithCompressionSetting(ImgTemp, newImagePath, 10L);
// Get the desired Codec
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
// Get the desired Encoder and Quality
private void SaveJPGWithCompressionSetting(Image image, string szFileName, long lCompression)
{
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lCompression);
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
image.Save(szFileName, ici, eps);
}