|
@@ -1021,19 +1021,22 @@ def PilImageToWxImage(pilImage, copyAlpha = True):
|
|
|
"""
|
|
|
import wx
|
|
|
hasAlpha = pilImage.mode[-1] == 'A'
|
|
|
- if copyAlpha and hasAlpha : # Make sure there is an alpha layer copy.
|
|
|
+ if copyAlpha and hasAlpha: # Make sure there is an alpha layer copy.
|
|
|
wxImage = wx.EmptyImage(*pilImage.size)
|
|
|
pilImageCopyRGBA = pilImage.copy()
|
|
|
pilImageCopyRGB = pilImageCopyRGBA.convert('RGB') # RGBA --> RGB
|
|
|
- pilImageRgbData = pilImageCopyRGB.tostring()
|
|
|
+ fn = getattr(pilImageCopyRGB, "tobytes", getattr(pilImageCopyRGB, "tostring"))
|
|
|
+ pilImageRgbData = fn()
|
|
|
wxImage.SetData(pilImageRgbData)
|
|
|
- wxImage.SetAlphaData(pilImageCopyRGBA.tostring()[3::4]) # Create layer and insert alpha values.
|
|
|
+ fn = getattr(pilImageCopyRGBA, "tobytes", getattr(pilImageCopyRGBA, "tostring"))
|
|
|
+ wxImage.SetAlphaData(fn()[3::4]) # Create layer and insert alpha values.
|
|
|
|
|
|
- else : # The resulting image will not have alpha.
|
|
|
+ else: # The resulting image will not have alpha.
|
|
|
wxImage = wx.EmptyImage(*pilImage.size)
|
|
|
pilImageCopy = pilImage.copy()
|
|
|
pilImageCopyRGB = pilImageCopy.convert('RGB') # Discard any alpha from the PIL image.
|
|
|
- pilImageRgbData = pilImageCopyRGB.tostring()
|
|
|
+ fn = getattr(pilImageCopyRGB, "tobytes", getattr(pilImageCopyRGB, "tostring"))
|
|
|
+ pilImageRgbData = fn()
|
|
|
wxImage.SetData(pilImageRgbData)
|
|
|
|
|
|
return wxImage
|