当使用 PIL python 库为高维 png 文件(770x1024)绘制矩形时,我在 draw.rectangle([x1, y1, x2, y2], fill="Black") 中遇到错误。但它适用于中等尺寸的图像。
img = Image.open(BytesIO(file_byte_string))
width, height = img.size
.
.
if(doc.pages):
page = doc.pages[0]
.
.
for field in page.form.fields:
if(field.key and field.value):
.
.
x1 = field.value.geometry.boundingBox.left*width
y1 = field.value.geometry.boundingBox.top*height-2
x2 = x1 + (field.value.geometry.boundingBox.width*width)+5
y2 = y1 + (field.value.geometry.boundingBox.height*height)+2
draw = ImageDraw.Draw(img)
draw.rectangle([x1, y1, x2, y2], fill="Black")
.
.
Run Code Online (Sandbox Code Playgroud)
示例 x1, y1, x2, y2 抛出错误:x1: 504.6949750185013 y1: 243.70870971679688 x2: 557.9484252631664 y2: 255.90338134765625
我该如何处理这个问题?我是否需要以编程方式调整大小或任何其他替代解决方案?
这是堆栈跟踪:
======================================================================
ERROR: …Run Code Online (Sandbox Code Playgroud)