【发布时间】:2011-09-06 13:04:10
【问题描述】:
我需要用 pyqt 读取 tga,到目前为止,这似乎工作正常,除了 tga 每个像素有 2 个字节而不是 3 或 4 个字节。我的代码取自这里http://pastebin.com/b5Vz61dZ。
特别是本节:
def getPixel( file, bytesPerPixel):
'Given the file object f, and number of bytes per pixel, read in the next pixel and return a qRgba uint'
pixel = []
for i in range(bytesPerPixel):
pixel.append(ord(file.read(1)))
if bytesPerPixel==4:
pixel = [pixel[2], pixel[1], pixel[0], pixel[3]]
color = qRgba(*pixel)
elif bytesPerPixel == 3:
pixel = [pixel[2], pixel[1], pixel[0]]
color = qRgb(*pixel)
elif bytesPerPixel == 2:
# if greyscale
color = QColor.fromHsv( 0, pixel[0] , pixel[1])
color = color.value()
return color
这部分:
elif bytesPerPixel == 2:
# if greyscale
color = QColor.fromHsv( 0, pixel[0] , pixel[1])
color = color.value()
如何输入像素[0] 和像素[1] 值以创建正确格式和色彩空间的值?
请有任何想法、想法或帮助!!!
【问题讨论】: