+%pythoncode {
+def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None):
+ """
+ Creates a `wx.Image` from the data in dataBuffer. The dataBuffer
+ parameter must be a Python object that implements the buffer
+ interface, such as a string, array, etc. The dataBuffer object is
+ expected to contain a series of RGB bytes and be width*height*3
+ bytes long. A buffer object can optionally be supplied for the
+ image's alpha channel data, and it is expected to be width*height
+ bytes long.
+
+ A reference to the data and alpha buffer objects are kept with the
+ wx.Image, so that they won't get deleted until after the wx.Image
+ is deleted. However please be aware that it is not guaranteed that
+ an object won't move its memory buffer to a new location when it
+ needs to resize its contents. If that happens then the wx.Image
+ will end up referring to an invalid memory location and could cause
+ the application to crash. Therefore care should be taken to not
+ manipulate the objects used for the data and alpha buffers in a
+ way that would cause them to change size.
+ """
+ if alphaBuffer is not None:
+ image = _ImageFromBufferWithAlpha(width, height, dataBuffer, alphaBuffer, None)
+ else:
+ image = _ImageFromBuffer(width, height, dataBuffer, None)
+ image._buffer = dataBuffer
+ image._alpha = alphaBuffer
+ return image
+}
+