Image Compression

using 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);
private void GenerateThumbnails(double nw,double nh, Stream sourcePath, string targetPath)
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”);


Artificial Intelligence and Data Science

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store