How do you write an annotation patch back onto a canvas?

paste overwrites the target in place starting at the given position. An optional mask restricts writes.

Pixel experiment and interpretation

Write two values into the middle of a four-cell strip. Copy the destination first when an untouched baseline must survive.

from PIL import Image

def row(values):
    return Image.frombytes('L', (len(values), 1), bytes(values))

im=row([0,0,0,0])
im.paste(row([5,9]),(1,0))
list(im.tobytes())

Result [0, 5, 9, 0]

中文

怎样把一块标注贴片写回原画布?

paste 在给定起点覆盖目标区域并直接修改目标图像,可选掩膜限制写入位置。

像素实验与适用边界

把两个亮度值写进四格底带的中间。需要保留未修改版本时,先复制底图再贴。

from PIL import Image

def row(values):
    return Image.frombytes('L', (len(values), 1), bytes(values))

im=row([0,0,0,0])
im.paste(row([5,9]),(1,0))
list(im.tobytes())

结果 [0, 5, 9, 0]

References / 参考来源

Keep reading / 继续阅读