<pre name="code" class="csharp"><span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>/// 任意变换图片
/// </summary>
/// <param name="oldBitmap">需要变换的图片</param>
/// <param name="newWidth">新宽度</param>
/// <param name="newHeight">新高度</param>
/// <returns></returns>
private static Bitmap GetNewBitmap(Bitmap oldBitmap, int newWidth, int newHeight)
{
Bitmap newBitmap = new Bitmap(newWidth, newHeight);
if (oldBitmap.Width == newWidth && oldBitmap.Height == newHeight) {
newBitmap = oldBitmap;
}
else {
Graphics g = Graphics.FromImage(newBitmap);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawImage(oldBitmap, new Rectangle(0, 0, newWidth, newHeight),
new Rectangle(0, 0, oldBitmap.Width, oldBitmap.Height),
GraphicsUnit.Pixel);
g.Dispose();
}
return newBitmap;
}