C#实现:图片转ICON图标,可放缩图像
By
jerrxjr1220
at 2023-08-08 • 0人收藏 • 357人看过
var bt = new Bitmap(@"C:\Users\xxx\Pictures\LOGO.png"); bt = bt.Resize(new Size(100, 50)); //扩展方法放缩图像 var icon = Icon.FromHandle(bt.GetHicon()); using (Stream stream = new System.IO.FileStream(@"C:\Users\xxx\Pictures\LOGO.ico", FileMode.Create)) { icon.Save(stream); } public static class myclass { public static Bitmap Resize(this Bitmap ori, Size newsize) { var newbt = new Bitmap(newsize.Width, newsize.Height); var graphics = System.Drawing.Graphics.FromImage(newbt); graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(ori, 0, 0, newsize.Width, newsize.Height); return newbt; } }
登录后方可回帖