此文记录的是图像操作的工具类。
/*** 图片工具类 Austin Liu 刘恒辉 Project Manager and Software Designer E-Mail: lzhdim@163.com Blog: http://lzhdim.cnblogs.com Date: 2024-01-15 15:18:00 使用方法例子: Bitmap originalImage = new Bitmap("path_to_image"); Bitmap resizedImage = ResizeImage(originalImage, 100, 100); resizedImage.Save("path_to_save_resized_image"); ***/ namespace Lzhdim.LPF.Utility { using System.Drawing; /// <summary> /// 图片工具类 /// </summary> internal class ImageUtil { /// <summary> /// 改变图片大小 /// </summary> /// <param name="original">原始图片</param> /// <param name="newWidth">新宽度</param> /// <param name="newHeight">新高度</param> /// <returns>图片</returns> public static Bitmap ResizeImage(Bitmap original, int newWidth, int newHeight) { // 创建一个新的Bitmap,其尺寸为新的尺寸 Bitmap resized = new Bitmap(newWidth, newHeight); using (Graphics g = Graphics.FromImage(resized)) { // 设置绘画质量 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(original, 0, 0, newWidth, newHeight); } return resized; } } }
Austin Liu 刘恒辉
Project Manager and Software Designer E-Mail:lzhdim@163.com Blog:https://lzhdim.cnblogs.com 欢迎收藏和转载此博客中的博文,但是请注明出处,给笔者一个与大家交流的空间。谢谢大家。 |