Image Compression
--
using C#.net(Window form)
private void button1_Click(object sender, EventArgs e)
{
string targetPath = “D:/” + sr;
FileStream fs = new FileStream(op.FileName, FileMode.Open, FileAccess.Read);
string targetFile = targetPath;
GenerateThumbnails(“Width vlue”,”Height value”, fs, targetFile);
MessageBox.Show(“Successfully”);
}
private void GenerateThumbnails(double nw,double nh, Stream sourcePath, string targetPath)
{
try
{
using (var image = Image.FromStream(sourcePath))
{
var newWidth = (int)(nw);
var newHeight = (int)(nh);
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}
}
catch (Exception )
{
MessageBox.Show(“Please Select Correct Image”);
}
}