views:

102

answers:

2

hello
how can i read image from clipboard ? i was only able to raed text using wx.clipboard. but not images
is it possible to read images with wx.clipboard?
or there is another way?

i use python2.5 and windows vita 64 bit

thanks in advance

A: 

Python Imaging Library has an ImageGrab module that can do just that. This works on windows only.

KillianDS
+1  A: 

The following works for me (tested on Mac OSX)

import wx
class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'test frame',size=(790, 524))
        self.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.clip = wx.Clipboard()
        self.x = wx.BitmapDataObject()
        self.bmp = None

    def OnClick(self, evt):
        self.clip.Open()
        self.clip.GetData(self.x)
        self.clip.Close()
        self.bmp = self.x.GetBitmap()
        self.Refresh()

    def OnPaint(self, evt):
        if self.bmp:
            dc = wx.PaintDC(self)
            dc.DrawBitmap(self.bmp, 20, 20, True)

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

To use this, I run it and when the frame comes up I copy an image using another program and then click in the wx frame, which then causes the copied image to be drawn within it.

tom10
+1, I use it for my app which works on both windows and OSX
Anurag Uniyal