本文整理汇总了Python中Image.frombuffer方法的典型用法代码示例。如果您正苦于以下问题:Python Image.frombuffer方法的具体用法?Python Image.frombuffer怎么用?Python Image.frombuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image.frombuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: array2PIL
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombuffer [as 别名]
def array2PIL(arr, size):
mode = 'RGBA'
arr = arr.reshape(arr.shape[0]*arr.shape[1], arr.shape[2])
if len(arr[0]) == 3:
arr = numpy.c_[arr, 255*numpy.ones((len(arr),1), numpy.uint8)]
return Image.frombuffer(mode, size, arr.tostring(), 'raw', mode, 0, 1)
示例2: save_screen
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombuffer [as 别名]
def save_screen(self,fn):
"""Saves a screenshot"""
try:
import Image
except ImportError:
print "Cannot save screens to disk, the Python Imaging Library is not installed"
return
screenshot = glReadPixels( 0,0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
im = Image.frombuffer("RGBA", (self.width, self.height), screenshot, "raw", "RGBA", 0, 0)
print "Saving screen to",fn
im.save(fn)
示例3: save_screen
# 需要导入模块: import Image [as 别名]
# 或者: from Image import frombuffer [as 别名]
def save_screen(self,fn):
"""Saves a screenshot"""
try:
import Image
except ImportError:
print("Cannot save screens to disk, the Python Imaging Library is not installed")
return
screenshot = glReadPixels( 0,0, self.width, self.height, GL_RGBA, GL_UNSIGNED_BYTE)
im = Image.frombuffer("RGBA", (self.width, self.height), screenshot, "raw", "RGBA", 0, 0)
print("Saving screen to",fn)
im.save(fn)