0
点赞
收藏
分享

微信扫一扫

C#把图片的白色背景转透明

徐一村 2022-03-12 阅读 202

原文链接: https://blog.csdn.net/weixin_30527423/article/details/96382563

public System.Drawing.Bitmap KnockOutGzf(String path)
{
    System.Drawing.Image image = System.Drawing.Image.FromFile(path);
    System.Drawing.Bitmap bitmapProxy = new System.Drawing.Bitmap(image);
    image.Dispose();
    for (int i = 0; i < bitmapProxy.Width; i++)
    {
        for (int j = 0; j < bitmapProxy.Height; j++)
        {
            System.Drawing.Color c = bitmapProxy.GetPixel(i, j);
            if (!(c.R < 240 || c.G < 240 || c.B < 240))
            {
                bitmapProxy.SetPixel(i, j, System.Drawing.Color.Transparent);
            }
        }
    }
    return bitmapProxy;
}
举报

相关推荐

0 条评论