本文整理汇总了Python中Image.frombytes方法的典型用法代码示例。如果您正苦于以下问题:Python Image.frombytes方法的具体用法?Python Image.frombytes怎么用?Python Image.frombytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.frombytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: arrayToImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombytes [as 别名]
def arrayToImage(a):
"""
Converts a gdalnumeric array to a
Python Imaging Library Image.
"""
i=Image.frombytes('L',(a.shape[1],a.shape[0]),
(a.astype('b')).tostring())
return i
示例2: renderArea
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombytes [as 别名]
def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
'''
'''
# NB: To be thread-safe Map object cannot be stored in the class state.
# see: https://groups.google.com/forum/#!topic/mapnik/USDlVfSk328
Map = mapnik.Map(width, height, srs)
Map.zoom_to_box(Box2d(xmin, ymin, xmax, ymax))
Map = self.style_map(Map)
img = mapnik.Image(width, height)
# Don't even call render with scale factor if it's not
# defined. Plays safe with older versions.
if self.scale_factor is None:
mapnik.render(Map, img)
else:
mapnik.render(Map, img, self.scale_factor)
def gamma_correct(im):
"""Fast gamma correction with PIL's image.point() method."""
if self.gamma != 1.0:
table = [pow(x / 255., 1.0 / self.gamma) * 255
for x in range(256)]
# Expand table to number of bands
table = table * len(im.mode)
return im.point(table)
else:
return im
# b = BytesIO(img.tostring())
img = Image.frombytes('RGBA', (width, height), img.tostring())
img = gamma_correct(img)
return img
示例3: arrayToImage
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombytes [as 别名]
def arrayToImage(a):
"""
Converts a gdalnumeric array to a
Python Imaging Library Image.
"""
i=Image.frombytes('L',(a.shape[1],a.shape[0]),
(a.astype('b')).tostring())
return i
# clip the raster only for tg halli area
# http://geospatialpython.com/2011/02/clip-raster-using-shapefile.html