C# 图片背景变为透明
今天遇到从身份证读取信息粘贴到身份证模板身份身份证图片的需求,但是获取的身份证头像是带背景色的所以需要去掉背景色。CSDN找了半天都是bitmap.MakeTransparent
这种只适用于纯色,但一般图片背景都不会是纯色就会很麻烦,只能通过遍历像素来修改像素点的颜色然后再透明。下面是效果和源码,小白第一次分享,有错误请大佬斧正。
原图
处理后
public static Image GetImage(Image image)
{
// 高度和宽度
int height = image.Height;
int width = image.Width;
// 生产背景透明和内容透明的图片