我们在(一)中的实现代码中,有备注的几个功能,为了让我们能看清楚功能,我先上传一张图片
#!/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
其实这是对图像各种功能的解说,可是我觉得呢,每次都要编一行,来代表获取图像的显示,很麻烦。能不能在框体里面设置一系列按钮,然后鼠标或键盘点击按钮触发事件来改变实现功能呢?