wxPython(二)功能拓展

我们在(一)中的实现代码中,有备注的几个功能,为了让我们能看清楚功能,我先上传一张图片

wxPython

#!/usr/bin/env python
import wx
import numpy as np
class Frame(wx.Frame):
    def __init__(self,image,parent=None,id=-1,pos=wx.DefaultPosition,title = 'Hello,wxPython!'):
        temp = image.ConvertToBitmap()
        size = temp.GetWidth(),temp.GetHeight()
#size = w,h
        wx.Frame.__init__(self,parent,id,title,pos,size)
        self.bmp = wx.StaticBitmap(parent=self,bitmap=temp)
class App(wx.App):
    def OnInit(self):
        #image = wx.Image('wxPython.jpg',wx.BITMAP_TYPE_JPEG)
        
        image = wx.Image('wxPython.jpg',wx.BITMAP_TYPE_ANY)
        w = image.GetWidth()
        h = image.GetHeight()
        image = image.Scale(w/2,h/2)缩小一半
        
        self.frame = Frame(image)
            
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True
            
def main():
    app = App()
    app.MainLoop()

if __name__=="__main__":
    main()

image = image.Scale(w/2,h/2),让图片缩小为原来图片的一半,我们可以操作w,h

如果要让它变成我们想要的具体想要的宽和高,可以直接用Rescale(w,h),w=200,h=150

image = image.Rescale(200,150)

这是改变宽度和高度的两个办法,当然我们想要的功能还要水平翻转和垂直翻转

水平翻转:

image = image.Mirror(horizontally = True)

垂直翻转:

image = image.Mirror(horizontally=False)

除了这个,我们也许还希望能旋转,那么简单的按90,180,270,的旋转很容易的,colockwise=True(顺时针)/False(逆时针)

image = image.Rotate90(clockwise = True)

当然有些时候,我们要的不是单纯的90,180,270度的旋转,而是要45度,或30度呢

        rota = wx.Point(w,h)
        image = image.Rotate(np.pi/4,rota,interpolating = True)

rota,是一个wx.Point对象

np.pi~3.14....,旋转的是弧度,np.pi是180,那么180/4=45

其实这是对图像各种功能的解说,可是我觉得呢,每次都要编一行,来代表获取图像的显示,很麻烦。能不能在框体里面设置一系列按钮,然后鼠标或键盘点击按钮触发事件来改变实现功能呢?

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值