如何使用wxpython调整大小和绘制图像? [英] How to resize and draw an image using wxpython?

查看:920
本文介绍了如何使用wxpython调整大小和绘制图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载图片,将其调整为给定大小,然后将其绘制到面板中的特定位置。

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

所有这些都使用wxpython。

All this using wxpython.

我该怎么办?

提前致谢!

推荐答案

wx.Image 有一个 Scale 方法,它将执行大小调整。其余的是正常的wx编码。

wx.Image has a Scale method that will do the resizing. The rest is normal wx coding.

这是一个完整的例子。

import wx

def scale_bitmap(bitmap, width, height):
    image = wx.ImageFromBitmap(bitmap)
    image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH)
    result = wx.BitmapFromImage(image)
    return result

class Panel(wx.Panel):
    def __init__(self, parent, path):
        super(Panel, self).__init__(parent, -1)
        bitmap = wx.Bitmap(path)
        bitmap = scale_bitmap(bitmap, 300, 200)
        control = wx.StaticBitmap(self, -1, bitmap)
        control.SetPosition((10, 10))

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1, 'Scaled Image')
    panel = Panel(frame, 'input.jpg')
    frame.Show()
    app.MainLoop()

这篇关于如何使用wxpython调整大小和绘制图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆