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