Skip to main content
 首页 » 编程设计

python之更改特定像素的颜色 [Wand]

2025年05月04日16grandyang

所以,我正在使用 Wand Python Library弄乱一些图像。

我只是希望它逐个像素地查看图像,对于特定颜色的每个像素,例如“4d4d4d”,将该像素颜色替换为其他颜色,例如“#00ff00”。就是这样。 我已经彻底搜索了文档,但我终究无法弄清楚如何执行此操作。

请您参考如下方法:

如果有人感兴趣,python 代码应该是这样的:

from wand.image import Image 
from wand.drawing import Drawing 
from wand.color import Color 
 
with Drawing() as draw: 
    draw.fill_color = Color('#00ff00') 
    draw.color(x,y,'replace') 
    with Image(filename='image.jpg') as img: 
        draw(img) 
        img.save(filename='new_image.jpg')