當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.fromstring方法代碼示例

本文整理匯總了Python中reqs.pil.Image.fromstring方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.fromstring方法的具體用法?Python Image.fromstring怎麽用?Python Image.fromstring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在reqs.pil.Image的用法示例。


在下文中一共展示了Image.fromstring方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load

# 需要導入模塊: from reqs.pil import Image [as 別名]
# 或者: from reqs.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
         )
開發者ID:Hetal728,項目名稱:SMP-ClassiCube,代碼行數:9,代碼來源:WmfImagePlugin.py

示例2: open

# 需要導入模塊: from reqs.pil import Image [as 別名]
# 或者: from reqs.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
開發者ID:Hetal728,項目名稱:SMP-ClassiCube,代碼行數:33,代碼來源:WalImageFile.py

示例3: grab

# 需要導入模塊: from reqs.pil import Image [as 別名]
# 或者: from reqs.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
開發者ID:Hetal728,項目名稱:SMP-ClassiCube,代碼行數:12,代碼來源:ImageGrab.py

示例4: _load_bitmaps

# 需要導入模塊: from reqs.pil import Image [as 別名]
# 或者: from reqs.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
開發者ID:Hetal728,項目名稱:SMP-ClassiCube,代碼行數:46,代碼來源:PcfFontFile.py

示例5: bdf_char

# 需要導入模塊: from reqs.pil import Image [as 別名]
# 或者: from reqs.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
開發者ID:Hetal728,項目名稱:SMP-ClassiCube,代碼行數:43,代碼來源:BdfFontFile.py


注:本文中的reqs.pil.Image.fromstring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。