How to resize and draw an image using wxpython?

前端 未结 3 650
感动是毒
感动是毒 2020-12-29 11:01

I want to load an image, resize it to a given size and after draw it in a specific position in a panel.

All this using wxpython.

How can I do it?

Tha

3条回答
  •  攒了一身酷
    2020-12-29 11:27

    First off I think the wxPython Docs and Demos do a great job explaining how to use their libraries, especially because the demos can be played with on the fly to see the affect or you can revert to the original. Here is the Windows link to download all the files:

    http://www.wxpython.org/download.php#binaries

    That said, here is the example code from the demo:

    def runTest(frame, nb, log):
        bmp = wx.Image(opj('bitmaps/image.bmp'), wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        gif = wx.Image(opj('bitmaps/image.gif'), wx.BITMAP_TYPE_GIF).ConvertToBitmap()
        png = wx.Image(opj('bitmaps/image.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        jpg = wx.Image(opj('bitmaps/image.jpg'), wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
    
        panel = wx.Panel(nb, -1)
    
        pos = 10
        wx.StaticBitmap(panel, -1, bmp, (10, pos), (bmp.GetWidth(), bmp.GetHeight()))
    
        pos = pos + bmp.GetHeight() + 10
        wx.StaticBitmap(panel, -1, gif, (10, pos), (gif.GetWidth(), gif.GetHeight()))
    
        pos = pos + gif.GetHeight() + 10
        wx.StaticBitmap(panel, -1, png, (10, pos), (png.GetWidth(), png.GetHeight()))
    
        pos = pos + png.GetHeight() + 10
        wx.StaticBitmap(panel, -1, jpg, (10, pos), (jpg.GetWidth(), jpg.GetHeight()))
    
        return panel
    

    Here it shows how to load an image and displays it on a panel. There are some objects not explained here, but it should give you the general gist.

提交回复
热议问题