在Windows上调用TIFFWriteEncodedStrip后整数除以零

2024-06-26 09:17:52 发布

您现在位置:Python中文网/ 问答频道 /正文

在python2.7中,我使用的是Pearu-Peterson开发的pylibtiff。我已经在我的路径中安装了libtiff3.dll等。我知道pylibtiff和libtiff已经超过5年了,但是它允许我控制TIFF文件的写入,比我能做的更多。tiffile.py文件由Christoph Gohlke开发。我更喜欢逐行处理数据,这在使用RowsPerStrip=1时是可能的。你知道吗

因此,我能够逐条读取TIFF文件,但不能以相同的方式写入。我想用同样的方法将数据写入磁盘,数据放在有限大小的缓冲区中。我希望我的代码最终能应用到大文件。第二次通过libtiff方法WriteEncodedStrip调用方法TIFFWriteEncodedStrip时,会出现“WindowsError:exception:integer除以零”。我做错什么了?你知道吗

from libtiff import TIFF
width = 600
height = 600
tif = TIFF.open('filename.tif', mode='w')
tif.SetField("ImageWidth", width)
tif.SetField("ImageLength", height)

# Set CCITTFAX3 settings etc.
tif.SetField("ImageWidth", width)
tif.SetField("ImageLength", height)
tif.GetField("RowsPerStrip", 1)
...

for i in range(height):
    # fill buffer
    buf = ...
    bytesPerStrip = math.ceil(width / 8)
    tif.WriteEncodedStrip(i, buf.ctypes.data, int(bytesPerStrip))

tif.WriteDirectory()
tif.close()

Tags: 文件数据方法widthheighttiftiffbuf