C#任意变换图像大小

来源:互联网 发布:office免费安装包 mac 编辑:程序博客网 时间:2024/06/05 04:56
<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;        }


                                             
0 0
原创粉丝点击