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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Nov 29, 2009, 11:31 PM
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);
}