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