本文整理汇总了Python中Image.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python Image.fromstring方法的具体用法?Python Image.fromstring怎么用?Python Image.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.fromstring方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fromstring
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def fromstring(self,s,width,height,format=imgformat.macrgb):
"""Stuff this pixmap with raw pixel data from a string.
Supply width, height, and one of the imgformat specifiers."""
# we only support 16- and 32-bit mac rgb...
# so convert if necessary
if format != imgformat.macrgb and format != imgformat.macrgb16:
# (LATER!)
raise "NotImplementedError", "conversion to macrgb or macrgb16"
self.data = s
self.bounds = (0,0,width,height)
self.cmpCount = 3
self.pixelType = QuickDraw.RGBDirect
if format == imgformat.macrgb:
self.pixelSize = 32
self.cmpSize = 8
else:
self.pixelSize = 16
self.cmpSize = 5
self.rowBytes = width*self.pixelSize/8
示例2: encode
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def encode(self, image, file, filename):
# File format is guessed from filename extension, otherwise defaults
# to PNG.
pil_format = (filename and os.path.splitext(filename)[1][1:]) or 'png'
if pil_format.lower() == 'jpg':
pil_format = 'JPEG'
image = image.get_image_data()
format = image.format
if format != 'RGB':
# Only save in RGB or RGBA formats.
format = 'RGBA'
pitch = -(image.width * len(format))
# Note: Don't try and use frombuffer(..); different versions of
# PIL will orient the image differently.
pil_image = Image.fromstring(
format, (image.width, image.height), image.get_data(format, pitch))
try:
pil_image.save(file, pil_format)
except Exception, e:
raise ImageEncodeException(e)
示例3: grab
# 需要导入模块: import Image [as 别名]
# 或者: from 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
##
# (New in 1.1.4) Take a snapshot of the clipboard image, if any.
#
# @return An image, a list of filenames, or None if the clipboard does
# not contain image data or filenames. Note that if a list is
# returned, the filenames may not represent image files.
# @since 1.1.4
示例4: WriteImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def WriteImage(image, outputPath):
if not hasPIL or not image: return False
out = []
for y in xrange(len(image[0])):
for x in xrange(len(image)):
out.append(DecAsc(image[x][y], 4))
out = Image.fromstring("RGBA", (len(image), len(image[0])), "".join(out))
filetype = outputPath[outputPath.rfind(".")+1:]
out.save(outputPath, filetype)
return True
#this is just for experimenting with sound decoding:
#not even remotely close to being finished
示例5: WriteImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def WriteImage(image, outputPath):
if not hasPIL or not image: return False
out = []
for y in xrange(len(image[0])):
for x in xrange(len(image)):
out.append(DecAsc(image[x][y], 4))
out = Image.fromstring("RGBA", (len(image), len(image[0])), "".join(out))
filetype = outputPath[outputPath.rfind(".")+1:]
out.save(outputPath, filetype)
return True
#Function ReadImage:
#
# Returns a 2D list of uint32 RGBA values of the image file.
# This can be passed into NTFT().SetImage()
#
# This function requires the PIl imaging module
示例6: showNaoImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def showNaoImage(IP, PORT):
"""
First get an image from Nao, then show it on the screen with PIL.
"""
camProxy = ALProxy("ALVideoDevice", IP, PORT)
cameraIndex = 0
resolution = 2 # VGA
colorSpace = 11 # RGB
videoClient = camProxy.subscribeCamera('python_client',0,resolution, colorSpace, 5)
t0 = time.time()
# Get a camera image.
# image[6] contains the image data passed as an array of ASCII chars.
naoImage = camProxy.getImageRemote(videoClient)
t1 = time.time()
# Time the image transfer.
print "acquisition delay ", t1 - t0
camProxy.unsubscribe(videoClient)
# Now we work with the image returned and save it as a PNG using ImageDraw
# package.
# Get the image size and pixel array.
imageWidth = naoImage[0]
imageHeight = naoImage[1]
array = naoImage[6]
# Create a PIL Image from our pixel array.
im = Image.fromstring("RGB", (imageWidth, imageHeight), array)
# Save the image.
im.save("camImage.png", "PNG")
im.show()
示例7: fromImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def fromImage(self,im):
"""Initialize this PixMap from a PIL Image object."""
# We need data in ARGB format; PIL can't currently do that,
# but it can do RGBA, which we can use by inserting one null
# up frontpm =
if im.mode != 'RGBA': im = im.convert('RGBA')
data = chr(0) + im.tostring()
self.fromstring(data, im.size[0], im.size[1])
示例8: toImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def toImage(self):
"""Return the contents of this PixMap as a PIL Image object."""
import Image
# our tostring() method returns data in ARGB format,
# whereas Image uses RGBA; a bit of slicing fixes this...
data = self.tostring()[1:] + chr(0)
bounds = self.bounds
return Image.fromstring('RGBA',(bounds[2]-bounds[0],bounds[3]-bounds[1]),data)
示例9: save
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def save(self,file=None):
self.w.update() # force image on screen to be current before saving it
pstring = glReadPixels(0,0,self.xpixels,self.ypixels,
GL_RGBA,GL_UNSIGNED_BYTE)
snapshot = Image.fromstring("RGBA",(self.xpixels,self.ypixels),pstring)
snapshot = snapshot.transpose(Image.FLIP_TOP_BOTTOM)
if not file: file = self.file
snapshot.save(file + ".png")
# --------------------------------------------------------------------
示例10: open
# 需要导入模块: import Image [as 别名]
# 或者: from 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
示例11: save
# 需要导入模块: import Image [as 别名]
# 或者: from Image import fromstring [as 别名]
def save(filename, width, height, fmt, pixels, flipped=False):
image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
if flipped:
image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
image.save(filename)
return True
# register
示例12: load
# 需要导入模块: import Image [as 别名]
# 或者: from 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
)
示例13: _load_bitmaps
# 需要导入模块: import Image [as 别名]
# 或者: from 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
示例14: bdf_char
# 需要导入模块: import Image [as 别名]
# 或者: from 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
##
# Font file plugin for the X11 BDF format.