1

I just want to display python image object in wxpython panel.

What i am trying to accomplish is taking screenshot using python ImageGrab or autopy and showing it in wxpython panel. My screenshot program running every second so there is no point save the image for wx.

import pyscreenshot as ImageGrab
imgobj = ImageGrab.grab()
print imgobj
# Convert into wximage
myWxImage = wx.EmptyImage( imgobj.size[0], imgobj.size[0] )
myWxImage.SetData( imgobj.convert( 'RGB' ).tostring())

Output

<Image.Image image mode=RGB size=1366x768 at 0x20B98F0> 
ValueError:Invalid data buffer size.

2 Answers 2

1

It's not easy to tell without a full traceback, but I think the issue might be this typo:

myWxImage = wx.EmptyImage( imgobj.size[0], imgobj.size[0] )

Should be:

myWxImage = wx.EmptyImage( imgobj.size[0], imgobj.size[1] )

Also you could make your code simpler with:

myWxImage = wx.ImageFromBuffer(imgobj.size[0], imgobj.size[1], imgobj.convert('RGB').tostring())
Sign up to request clarification or add additional context in comments.

Comments

0

I assume your problem is that you are passing the image width as new height to wx...

And btw instead you could use

myWxImage = wx.ImageFromBuffer( imgobj.size[0], imgobj.size[1], imgobj.tostring() )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.