C#
Sometimes we want to save an image of a given dimension.
Below method 'resizeImage' is to resizing the image 'imgToResize' for a given size 'size'
private static Image resizeImage(Image imgToResize, Size size)
{
int destWidth = size.Width;
int destHeight = size.Height ;
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (Image)b;
}
The above method can be utilized as -
Image imgOriginal = new Image.FromFile(imgFilePath);
Image imgResized = this.resizeImage(imgOriginal , new Size(100,100));
imgResized.Save(SaveToFilepath);
Now for any size of original image we will get an image of size 100 * 100.
No comments:
Post a Comment