1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/// <summary>
/// Resizes the pic by width.
/// </summary>
/// <param name="sourceImage">The source image.</param>
/// <param name="newWidth">The new width.</param>
/// <returns></returns>
private static Bitmap ResizePicByWidth(Image sourceImage, double newWidth)
{
double sizeFactor = newWidth/sourceImage.Width;
double newHeigth = sizeFactor*sourceImage.Height;
Bitmap newImage = new Bitmap((int) newWidth, (int) newHeigth);
using (Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(sourceImage, new Rectangle(0, 0, (int) newWidth, (int) newHeigth));
}
return newImage;
}
|