When can editing the input buffer change a pixel reading?
For supported modes and layouts, frombuffer can reference the original buffer without copying samples.
Pixel experiment and interpretation
A sensor reusing a grayscale byte buffer can change a previously created view on its next write. Copy the frame first when retaining a baseline.
from PIL import Image
raw=bytearray([1,2])
im=Image.frombuffer('L',(2,1),raw,'raw','L',0,1)
raw[0]=90
im.getpixel((0,0))Result 90
中文
什么情况下修改输入缓冲区会改变图像读数?
frombuffer 在支持共享内存的模式及布局下可引用原始缓冲区,而无需复制像素。
像素实验与适用边界
灰度传感器复用一块字节区时,下一次写入会改变已有视图。要留作上一帧基线,需先独立复制。
from PIL import Image
raw=bytearray([1,2])
im=Image.frombuffer('L',(2,1),raw,'raw','L',0,1)
raw[0]=90
im.getpixel((0,0))结果 90