Wand的像素迭代器缺乏将颜色数据“同步”回ImageMagick的“真实”像素数据流的能力。在
您可以实现一个导入像素数据流,like this question(类似的问题经常被问到)。在
或者使用wand.drawing.DrawingAPI。在from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
with Drawing() as ctx:
colors = ["RED", "GREEN", "BLUE", "WHITE"]
for index, color_name in enumerate(colors):
ctx.push() # Grow context stack
ctx.fill_color = Color(color_name) # Allocated color
ctx.point(index % 2, index / 2) # Draw pixel
ctx.pop() # Reduce context stack
with Image(width=2, height=2, background=Color("NONE")) as img:
ctx.draw(img)
img.sample(100,100)
img.save(filename="output.png")