- 浏览: 551142 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (344)
- ··············未分类············· (33)
- Eclipse 插件 (15)
- EDA 工具 (1)
- Linux/Unix (3)
- Java (43)
- Java Applet (1)
- Java Draw2d (22)
- Java Draw2d version2 (6)
- Java GEF (2)
- Java SWT (21)
- Java SWT Image 图像 (21)
- Java SWT Tree (16)
- Java SWT Table (4)
- Java SWT TableViewer (11)
- Java SWTbot (4)
- Java Test (2)
- Java Thread 多线程 (22)
- Java Zest (5)
- RC2_3S400学习笔记 (16)
- tcl 脚本 (10)
- Verilog (7)
- XML (6)
- 国家 (5)
- 感叹 (4)
- 面试题 (9)
- 生活 (36)
- 足球 世界杯 (8)
- 老公看你的 (3)
- web开发 (1)
- 数据结构——图 (7)
- c language (1)
最新评论
-
zxjlwt:
路过素人派http://surenpi.com
SWT 树的事件 SWT.Selection SWT.CHECK SWT.DefaultSelection -
hj01kkk:
1楼用法正解
JDK 7 中的 Fork/Join 模式 -
fish_no7:
使用 new SortTask().fork()
JDK 7 中的 Fork/Join 模式 -
wpf523:
mark
Java 多线程例子6 线程安全 线程同步 同步代码块 同步函数 -
uniquejava:
以前碰到过,估计是在icu包中实现了双击自动选中一段文本的功能 ...
java.lang.NoClassDefFoundError: com/ibm/icu/text/BreakIterator
/******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.snippets; /* * Use transformation matrices to reflect, rotate and shear images * * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ */ import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class Snippet207 { public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("HOV", 10, 10, true); gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); gc.fillRectangle(0, 0, 10, 10); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener () { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()){ gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA)); // gc.drawLine(20, 20, 580, 580); // gc.drawImage(image, x, y); Transform transform = new Transform(display); // transform.setElements(1, 0, 0, 1, 0 ,0); transform.scale(1, 1); // transform.translate(0.5f, 0.5f); // transform.invert(); gc.setTransform(transform); gc.drawImage(image, x, y); x += rect.width + 30; // Note that the tranform is applied to the whole GC therefore // the coordinates need to be adjusted too. // Reflect around the y axis. transform.setElements(-1, 0, 0, 1, 0 ,0); gc.setTransform(transform); //(-30-110-30-110,30) gc.drawImage(image, -1*x-rect.width, y); x = 30; y += rect.height + 30; // Reflect around the x axis. transform.setElements(1, 0, 0, -1, 0, 0); gc.setTransform(transform); //(30,-30-60-30-60) gc.drawImage(image, x, -1*y-rect.height); x += rect.width + 30; // Reflect around the x and y axes transform.setElements(-1, 0, 0, -1, 0, 0); gc.setTransform(transform); //(-30-110-30-110,-30-60-30-60) gc.drawImage(image, -1*x-rect.width, -1*y-rect.height); x = 30; y += rect.height + 30; // Shear in the x-direction transform.setElements(1, 0, -1, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 300, y); // Shear in y-direction transform.setElements(1, -1, 0, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 170, 475); // Rotate by 45 degrees float cos45 = (float)Math.cos(Math.PI/4); float sin45 = (float)Math.sin(Math.PI/4); System.out.println(cos45); System.out.println(sin45); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc.setTransform(transform); gc.drawImage(image, 250, 150); /* // Shear in x-y-direction transform.setElements(1, 1, 0, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 170, 195); // Shear in x-y-direction transform.setElements(1, 1, 0, 1, 0, 0); gc.setTransform(transform); gc.drawImage(image, 280, -85); // Shear in y-direction transform.setElements(1, -1, 0, 1, 0, 0); // transform.translate(20, 20); gc.setTransform(transform); gc.drawImage(image, 280, 755); // gc.setTransform(transform); // gc.drawText("20,20", 20, 20, true); transform = new Transform(display); transform.rotate(30); gc.setTransform(transform); gc.drawImage(image, 350, 0); */ transform.dispose(); } }); shell.setSize(600, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); } }
1,Instances of this class represent transformation matrices for points expressed as (x, y) pairs of floating point numbers.
org.eclipse.swt.graphics(package)
例子:org.eclipse.swt.snippets.Snippet207
实现:Use transformation matrices to reflect, rotate and shear images
Transform其实就是实现了坐标的转换,其实并没有改变图像本身。具体怎么改的我只是猜测,并在猜测后用程序去验证我的猜测。
Transform用途有:(这些都是针对于图像的)
1,放大,缩小。
2,旋转一定得角度。
3,根据矩形运算完成图像变换,X对称,Y对称,Y=X对称等等。
注意点:
1,Transform的变换是基于坐标系的变换,所以对所有点有效。这里要特别指出的是图像的起始坐标,也应跟着变换了。(简单想,不是太好理解,要认真分析Snippet207就可以看出)
2,
如何使用:
1,放大,缩小——scale(3,3)放大为原来的三倍。 scale(0.5f,0.5f)为1/2. 这里与ImageData的scaledTo不同,ImageData只是针对于图像变换,这是坐标系变大。
2,旋转一定得角度——rotate(45) 旋转45度,这里的參数直接是度数,而Math.cos()里面使用的弧度。坐标也转45度。
3,矩形运算——最复杂也最灵活。setElements(float m11, float m12, float m21, float m22, float dx, float dy)
transform.setElements(1, 0, 0, 1, 0 ,0)——原图不变。
transform.setElements(-1, 0, 0, 1, 0 ,0)——得到与原图Y对称的图。
transform.setElements(1, 0, 0, -1, 0 ,0)——得到与原图X对称的图。
transform.setElements(-1, 0, 0, -1, 0 ,0)——得到与原图Y=x对称的图。
transform.setElements(1, 0, -1, 1, 0 ,0)——X轴不变,Y轴向左转45度 的图。
transform.setElements(1, -1, 0, 1, 0 ,0)——Y轴不变,X轴向上转45度 的图。
上图就是Snippet207的效果图:
①,原图。
②,Y对称。
③,X对称。
④,Y=X对称。
⑤,X轴不变,Y轴向左转45度。
⑥,Y轴不变,X轴向上转45度。
⑦,X轴Y轴一起顺时针转45度,也可以看着是图像转。所以,transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);和transform.rotate(30);等价。
矩阵运算的原理:
首先,看API文档上说了。
m11 - the first element of the first row of the matrix
m12 - the second element of the first row of the matrix
m21 - the first element of the second row of the matrix
m22 - the second element of the second row of the matrix
dx - the third element of the first row of the matrix
dy - the third element of the second row of the matrix
也就是说表示的矩形为,这里先不说dx和dy,马上最后说。
所以这里的坐标变换就成了。
(1, 0, 0, 1, 0 ,0)——(X,Y)——原图不变。
(-1, 0, 0, 1, 0 ,0)——(-X,Y)——得到与原图Y对称的图。
(1, 0, 0, -1, 0 ,0)——(X,-Y)——得到与原图X对称的图。
(-1, 0, 0, -1, 0 ,0)——(-X,-Y)——得到与原图Y=x对称的图。
(1, 0, -1, 1, 0 ,0)——(X-Y,Y)——X轴不变,Y轴向左转45度 的图。
(1, -1, 0, 1, 0 ,0)——(X,-X+Y)——Y轴不变,X轴向上转45度 的图。
上图展示了三种对称图。
对于其他如“(1, 0, -1, 1, 0 ,0)——(X-Y,Y)——X轴不变,Y轴向左转45度 的图”和“(1, -1, 0, 1, 0 ,0)——(X,-X+Y)——Y轴不变,X轴向上转45度 的图”我是采用点带入计算然后总结出坐标系的变换的。如下图:
这就是“(1, 0, -1, 1, 0 ,0)——(X-Y,Y)——X轴不变,Y轴向左转45度 的图”的变换。我取了四个点【(0,0),(0,Y),(X,0),(X,Y)】这样就可很明显地看出等价的坐标系的变换。当然“(1, -1, 0, 1, 0 ,0)——(X,-X+Y)——Y轴不变,X轴向上转45度 的图”也是同理了。所以,在遇到这个矩阵变换看不懂知道用这种方法就可以看出来。
最后说一下这个dx和dy,其实看了上面的坐标变换就可以很好想象dx和dy了。dx和dy就是实现坐标系的平移了。加入dx和dy,转换的公式就变成了:
再提一下还有个函数translate(float offsetX, float offsetY),这个的offsetX和offsetY就相当于dx和dy,这样就好理解了。
关于Transform基本上就讲完了,这里多说一下应用,矩形变化可以应用于任何的坐标系的变换。
这里补充一下为什么,(X,Y)旋转后,坐标变为了呢?顺便复习一下数学知识。
角坐标系和直角坐标系对应
所以:
当然Y也同理了。
发表评论
-
定制tooltip
2013-10-06 18:17 712public class HelloToolTip { ... -
java SWT StackLayout
2013-09-16 17:40 818public class UsingStackLayout ... -
JFace snippet
2013-01-31 11:00 1378附件有org.eclipse.jface.snippets, ... -
SWT 中Button和Label重叠放置
2011-12-30 17:18 2673写了一个小例子: public class Snipp ... -
SWT DND的Snippet 和 剪贴板
2011-11-15 19:50 2234链接:http://www.eclipse.org/swt/s ... -
display.getSystemColor 中的颜色
2011-10-28 20:41 1244记得以前好像记录过,就是找不到了。 public c ... -
SWT程序需要导入的jar
2011-10-12 18:04 11491,org.eclipse.swt.win32.x86_xxx ... -
用滚动的字符表示Task的运行,比较ProgressMonitorDialog
2011-08-16 17:55 3189JFace中的提供的ProgressMonitorDialog ... -
SWT 的对话框模式与非模式
2011-05-24 16:03 1959关键字:SWT 对话框 模式 非模式 SWT.MODELESS ... -
Java SWT SWTChart坐标图
2010-12-13 14:02 4525关键字: SWTChart 坐标图 链接:http://w ... -
java.lang.NoClassDefFoundError: com/ibm/icu/text/BreakIterator
2010-11-25 14:00 3150关键字:java.lang.NoClassDefFoundE ... -
类似百度和谷歌那样的自动提示组合框
2010-09-30 14:04 1346问题:http://www.iteye.com/problem ... -
SWT表格列随着控件变化自动变化
2010-07-08 17:23 2099源程序来自:snippet77 /********** ... -
一个日历程序 可农历到公历 公历到农历 第几周 显示节气
2010-07-02 20:01 2586public class Sample3 { privat ... -
一个简单的时钟程序
2010-07-02 19:24 1092public class Sample2 { privat ... -
计分器
2010-07-02 17:28 1140代码: public class Sample1 { p ... -
SWT资料
2010-06-30 19:24 832SWT-jface一些例子: http://www.j ... -
事件管理器 4个象限【还没有完成】
2010-06-23 17:12 11231,改完成了一个大概的样子,还要把Text改成List,可以添 ... -
利用SWT内部的图标
2010-06-23 16:55 2914import org.eclipse.swt.SWT; im ... -
SWT 浏览器
2010-06-23 16:48 2764这个来自书上的一个例子: package firstSWT ...
相关推荐
Practical.Transformation.with.XSLT.and.XPath
Sybase.Modeling.Transformation.dll.descriptor
吴恩达-AI-Transformation-Playbook.pdf
python库。 资源全名:SW-transformation-0.0.1.tar.gz
OpenCV_Pic_Perspective_Transformation-master.zip
Beginning-Python-Visualization-Crafting-Visual-Transformation-Scripts.pdf
用FPGA实现FFT算法 引言 DFTDiscrete Fourier Transformation是数字.doc
信号与系统教学课件:1-3 Transformation of variables.ppt
Beginning_Python_Visualization__Crafting_Visual_Transformation_Scripts.pdf
coordinate conversions transformation including formulas there is very useful.
WINDOWS仿真MAC的桌面和UI,仿真度高,外观优质,占用内存一般。
Gray scale enhancement methods
One exemple of inverse transformation
RGB空间和YCBCR空间之间的转换以及NTSC空间和RGB空间的转换
AI-Transformation-Playbook
图像变换实验,掌握图像傅里叶变换的方法及应用,利用MATLAB实现数字图像的频域处理
Sybase.Modeling.Transformation.Bpmn2.dll.descriptor
使用matlab语言采用傅里叶变换技术实现图像变换