Python Image.frombuffer() Examples

The following are 3 code examples of Image.frombuffer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Image , or try the search function .
Example #1
Source File: recipe-577591.py    From code with MIT License 5 votes vote down vote up
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) 
Example #2
Source File: qtprogram.py    From pyOptimalMotionPlanning with Apache License 2.0 5 votes vote down vote up
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) 
Example #3
Source File: glprogram.py    From pyOptimalMotionPlanning with Apache License 2.0 5 votes vote down vote up
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)