本文整理匯總了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):