wxPython(二)功能拓展
2018-12-05 01:17
78 查看
我们在(一)中的实现代码中,有备注的几个功能,为了让我们能看清楚功能,我先上传一张图片
[code]#!/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
[code]image = image.Rescale(200,150)
这是改变宽度和高度的两个办法,当然我们想要的功能还要水平翻转和垂直翻转
水平翻转:
[code]image = image.Mirror(horizontally = True)
垂直翻转:
[code]image = image.Mirror(horizontally=False)
除了这个,我们也许还希望能旋转,那么简单的按90,180,270,的旋转很容易的,colockwise=True(顺时针)/False(逆时针)
[code]image = image.Rotate90(clockwise = True)
当然有些时候,我们要的不是单纯的90,180,270度的旋转,而是要45度,或30度呢
[code] 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
其实这是对图像各种功能的解说,可是我觉得呢,每次都要编一行,来代表获取图像的显示,很麻烦。能不能在框体里面设置一系列按钮,然后鼠标或键盘点击按钮触发事件来改变实现功能呢?
阅读更多
相关文章推荐
- 接口实现分离(漫谈C#和swift的部分实现拓展功能)
- 转:VS2005的DataGridView 多维合并标题 功能拓展
- 【C++11】C++类型完全退化(拓展std::decay的功能)
- synchronized的功能拓展:重入锁(读书笔记)
- 【wxPython】wxPython实现列表增删改查功能
- Oracle group by 基本及的拓展 ROLLUP, CUBE, GROUPING 功能and GROUPING 集合
- openlayers3功能拓展
- jQuery Validate表单验证插件的基本使用方法及功能拓展
- MyEclipse 10.x中拓展自动提示功能
- 拓展编辑器功能--Unity自定义编辑器窗口
- 腾讯通RTX拓展功能
- 拓展C++ STL功能,函数适配器,复合函数composite
- 2015华为软赛(六)——拓展功能函数
- Unity3D之Shader自定义编辑器功能拓展
- Android中探究抖音短视频的动态壁纸功能以及拓展功能使用
- 第八周实验报告(一)《方案三》拓展运算符功能
- nodejs包typings拓展自动补全功能
- Spring源码阅读(四)—容器的功能拓展ApplicationContext
- MyEclipse 10.7中拓展自动提示功能
- NLP︱词向量经验总结(功能作用、高维可视化、R语言实现、大规模语料、延伸拓展)