本文整理汇总了Python中lib.pil.Image.frombuffer方法的典型用法代码示例。如果您正苦于以下问题:Python Image.frombuffer方法的具体用法?Python Image.frombuffer怎么用?Python Image.frombuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.pil.Image
的用法示例。
在下文中一共展示了Image.frombuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import frombuffer [as 别名]
sig = fobj.read(4)
if sig != '\x00\x00\x00\x00':
raise SyntaxError, 'Unknown signature, expecting 0x00000000'
return read_32(fobj, (start + 4, length - 4), (width, height))
def read_32(fobj, (start, length), size):
"""
Read a 32bit RGB icon resource. Seems to be either uncompressed or
an RLE packbits-like scheme.
"""
fobj.seek(start)
sizesq = size[0] * size[1]
if length == sizesq * 3:
# uncompressed ("RGBRGBGB")
indata = fobj.read(length)
im = Image.frombuffer("RGB", size, indata, "raw", "RGB", 0, 1)
else:
# decode image
im = Image.new("RGB", size, None)
for band_ix in range(3):
data = []
bytesleft = sizesq
while bytesleft > 0:
byte = fobj.read(1)
if not byte:
break
byte = ord(byte)
if byte & 0x80:
blocksize = byte - 125
byte = fobj.read(1)
for i in range(blocksize):