Which pixels change when a panel mask gains rounded corners?

rounded_rectangle rounds a box's corners to a given radius while retaining the straight edge sections and filled center.

Pixel experiment and interpretation

Probe a corner and the midpoint of the top edge in a button hit mask. The rounded mask disagrees with the bounding box near the corners.

from PIL import Image, ImageDraw

im=Image.new('L',(11,7))
ImageDraw.Draw(im).rounded_rectangle((0,0,10,6),radius=3,fill=1)
[im.getpixel(p) for p in [(0,0),(5,0)]]

Result [0, 1]

中文

生成圆角面板掩膜时 radius 改变了哪些像素?

rounded_rectangle 在矩形四角应用给定半径,平直边段与中心仍可填充。

像素实验与适用边界

用角点和上边中点检查按钮的点击区域;圆角遮罩和外接矩形在拐角处会给出不同答案。

from PIL import Image, ImageDraw

im=Image.new('L',(11,7))
ImageDraw.Draw(im).rounded_rectangle((0,0,10,6),radius=3,fill=1)
[im.getpixel(p) for p in [(0,0),(5,0)]]

结果 [0, 1]

References / 参考来源

Keep reading / 继续阅读