本文整理汇总了Python中lib.pil.Image.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python Image.fromstring方法的具体用法?Python Image.fromstring怎么用?Python Image.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.pil.Image
的用法示例。
在下文中一共展示了Image.fromstring方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import fromstring [as 别名]
def open(filename):
# FIXME: modify to return a WalImageFile instance instead of
# plain Image object ?
if hasattr(filename, "read"):
fp = filename
else:
import __builtin__
fp = __builtin__.open(filename, "rb")
# read header fields
header = fp.read(32+24+32+12)
size = i32(header, 32), i32(header, 36)
offset = i32(header, 40)
# load pixel data
fp.seek(offset)
im = Image.fromstring("P", size, fp.read(size[0] * size[1]))
im.putpalette(quake2palette)
im.format = "WAL"
im.format_description = "Quake2 Texture"
# strings are null-terminated
im.info["name"] = header[:32].split("\0", 1)[0]
next_name = header[56:56+32].split("\0", 1)[0]
if next_name:
im.info["next_name"] = next_name
return im
示例2: load
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import fromstring [as 别名]
def load(self, im):
im.fp.seek(0) # rewind
return Image.fromstring(
"RGB", im.size,
Image.core.drawwmf(im.fp.read(), im.size, self.bbox),
"raw", "BGR", (im.size[0]*3 + 3) & -4, -1
)
示例3: grab
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import fromstring [as 别名]
def grab(bbox=None):
size, data = grabber()
im = Image.fromstring(
"RGB", size, data,
# RGB, 32-bit line padding, origo in lower left corner
"raw", "BGR", (size[0]*3 + 3) & -4, -1
)
if bbox:
im = im.crop(bbox)
return im
示例4: _load_bitmaps
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import fromstring [as 别名]
def _load_bitmaps(self, metrics):
#
# bitmap data
bitmaps = []
fp, format, i16, i32 = self._getformat(PCF_BITMAPS)
nbitmaps = i32(fp.read(4))
if nbitmaps != len(metrics):
raise IOError, "Wrong number of bitmaps"
offsets = []
for i in range(nbitmaps):
offsets.append(i32(fp.read(4)))
bitmapSizes = []
for i in range(4):
bitmapSizes.append(i32(fp.read(4)))
byteorder = format & 4 # non-zero => MSB
bitorder = format & 8 # non-zero => MSB
padindex = format & 3
bitmapsize = bitmapSizes[padindex]
offsets.append(bitmapsize)
data = fp.read(bitmapsize)
pad = BYTES_PER_ROW[padindex]
mode = "1;R"
if bitorder:
mode = "1"
for i in range(nbitmaps):
x, y, l, r, w, a, d, f = metrics[i]
b, e = offsets[i], offsets[i+1]
bitmaps.append(
Image.fromstring("1", (x, y), data[b:e], "raw", mode, pad(x))
)
return bitmaps
示例5: bdf_char
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import fromstring [as 别名]
def bdf_char(f):
# skip to STARTCHAR
while 1:
s = f.readline()
if not s:
return None
if s[:9] == "STARTCHAR":
break
id = string.strip(s[9:])
# load symbol properties
props = {}
while 1:
s = f.readline()
if not s or s[:6] == "BITMAP":
break
i = string.find(s, " ")
props[s[:i]] = s[i+1:-1]
# load bitmap
bitmap = []
while 1:
s = f.readline()
if not s or s[:7] == "ENDCHAR":
break
bitmap.append(s[:-1])
bitmap = string.join(bitmap, "")
[x, y, l, d] = map(int, string.split(props["BBX"]))
[dx, dy] = map(int, string.split(props["DWIDTH"]))
bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)
try:
im = Image.fromstring("1", (x, y), bitmap, "hex", "1")
except ValueError:
# deal with zero-width characters
im = Image.new("1", (x, y))
return id, int(props["ENCODING"]), bbox, im