您的位置:首页 > 编程语言 > C#

C#任意变换图像大小

2016-07-07 18:43 351 查看
<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;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息