下面是"M276,189h268c5.5,0,10,4.5,10,10v196c0,5.5-4.5,10-10,10H276 c-5.5,0-10-4.5-10-10V199C266,193.5,270.5,189,276,189z“的路径
这是输入图像:
使用下面的代码将路径应用到图像之后
draw = Magick::Draw.new
draw.fill 'red'
draw.path path
draw.clip_rule("evenodd")
draw.fill_rule("evenodd")
draw.fill_opacity(0)
draw.draw image
img.trim!
img.write('output.jpg')
这是输出图像:
现在我想要剪切图像的红色部分。这意味着只能看到棕色部分。我使用了普通的图像级裁剪方法。用这个我只能提取红色部分,但我想从输出图像中提取红色以外的图像。
下面是黑色图像sample output for the black color的示例输出
也许我们必须反转剪辑或反转裁剪才能得到这个...
发布于 2020-06-12 00:28:31
该方法
img.paint_transparent
将使红色部分成为透明的,但我们必须将颜色作为参数传递给上面的方法。最初,我尝试将颜色值设置为红色。所以它不起作用。现在我从图像中读取一个像素,如下所示
redPixel= img.get_pixels(300,200,1,1)
并从类似像素的redPixel.to_color中获取颜色,并将值传递给上面的方法...
我们必须为图像设置模糊值
img = Magick::Image.read("diecut.jpg").first
redPixel= img.get_pixels(300,200,1,1)
img.fuzz = '25%‘
将redPixel.to_color放入
newimage=img.paint_transparent(redPixel.to_color)
newimage.write("outPut.png")
newimage.display
https://stackoverflow.com/questions/62319848
复制相似问题