博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#将图片背景从透明变成白色
阅读量:4568 次
发布时间:2019-06-08

本文共 1156 字,大约阅读时间需要 3 分钟。

var img = System.Drawing.Image.FromStream(ms);                            int width = img.Width;                            int height = img.Height;                            var x = img.HorizontalResolution;                            var y = img.VerticalResolution;                            var tempHeight = height * 300 / y;                            var tempWidth = width * 300 / y;                            Bitmap bmpTemp = new Bitmap((int)tempWidth, (int)tempHeight);                            Graphics g = Graphics.FromImage(bmpTemp);                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;                            g.Clear(System.Drawing.Color.White);                            g.DrawImage(img, new RectangleF(0, 0, tempWidth, tempHeight), new RectangleF(0, 0, width, height), GraphicsUnit.Pixel);                            g.Save();                            bmpTemp.Save(target, ImageFormat.Png);                            g.Dispose();                            img.Dispose();                            bmpTemp.Dispose();

 

感谢每一位阅读此篇文章的人,希望可以帮到你。

转载于:https://www.cnblogs.com/chlm/p/5619477.html

你可能感兴趣的文章
MS SQL 统计信息浅析上篇
查看>>
YourSQLDba版本升级总结
查看>>
Failure sending mail: The user or group name 'xxx\xxxx' is not recognized.Mail will not be resent
查看>>
分析函数改写自关联
查看>>
appium 数据参数化 登录模块
查看>>
php内置函数分析之array_fill_keys()
查看>>
git 从远程仓库获取所有分支
查看>>
从 Godaddy 转移域名到 Namesilo
查看>>
numpy
查看>>
django | 连接mysql数据库
查看>>
导入sql时报日期类型错误
查看>>
更改arch的默认终端
查看>>
labelme2coco问题:TypeError: Object of type 'int64' is not JSON serializable
查看>>
JDBC连接MySQL数据库的方法和实例
查看>>
初学python之感悟
查看>>
(转)Secondary NameNode的作用
查看>>
Unable to read TLD "META-INF/c.tld" from JAR file
查看>>
React开发
查看>>
权限管理
查看>>
Python字符串操作
查看>>