C#学习教程:用PNG图像中的白色替换透明背景分享

您所在的位置:网站首页 透明背景的png图片怎么改为50kb C#学习教程:用PNG图像中的白色替换透明背景分享

C#学习教程:用PNG图像中的白色替换透明背景分享

2023-04-22 19:11| 来源: 网络整理| 查看: 265

用PNG图像中的白色替换透明背景

我有一个PNG图像从Android中的DrawingView发送到WCF服务。 图像以32位发送,并具有透明背景。 我想用白色替换透明色(缺少更好的单词)背景。 到目前为止我的代码看起来像这样:

// Converting image to Bitmap object Bitmap i = new Bitmap(new MemoryStream(Convert.FromBase64String(image))); // The image that is send from the tablet is 1280x692 // So we need to crop it Rectangle cropRect = new Rectangle(640, 0, 640, 692); //HERE Bitmap target = i.Clone(cropRect, i.PixelFormat); target.Save(string.Format("c:\images\{0}.png", randomFileName()), System.Drawing.Imaging.ImageFormat.Png);

以上工作正常,但图像具有透明背景。 我注意到在Paint.NET中你可以简单地将PNG格式设置为8位,并将背景设置为白色。 但是,当我尝试使用时:

System.Drawing.Imaging.PixelFormat.Format8bppIndexed

我得到的只是一张完全黑色的照片。

问:如何在png中用白色替换透明背景?

PS。 图像为灰度。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3