以编程方式使用 imagemagick 将图像的背景转换为透明

Converting Background of a Image to transparent Using imagemagick programaticaly

我正在尝试将图像的所有 白色 背景(使用插件从 Html 生成)转换为透明 这样我就可以把它当作邮票了

Using image As MagickImage = New MagickImage(filenamelocation)
                    image.Alpha(AlphaOption.Set)
                    image.ColorFuzz = New Percentage(40)
                    image.Settings.BackgroundColor = MagickColors.Transparent
                    image.Settings.FillColor = MagickColors.White
                    image.FloodFill(MagickColors.Transparent, 0, 0)   
                    image.Write(Path.Combine(Server.MapPath("~/Uploads/attachment/"), "stampimagename.png"))
                End Using

我正在使用 ImageMagick nuget 包做同样的事情,需要将所有白色转换为透明 只剩下蓝色项目显示,有人可以建议我做错了什么吗

我认为您不应该将背景声明为透明然后用白色填充(不太确定这到底是什么意思..)

据我阅读执行此操作的命令行操作(并翻译为 VB;似乎大多数命令行和 VB 相似),您应该加载图像,声明白色为透明色,可能带有一些模糊因素,然后将其保存为支持透明的格式:

Using image As MagickImage = New MagickImage(filenamelocation)

    image.ColorFuzz = new Percentage(10) 'declare a lower fuzz factor
    img.Transparent(MagickColors.White) 'declare that the transparency should apply to anything that is white 
    img.Write("image.png") 'save as a format that support transparency. jpg does not

End Using