我有一张大的图片 想在SWT中这张大图创建的image 截取能几个小的image 应该怎么做啊 请各位大大指教···
解决方案 »
- javascript传数据问题 急急在线等
- 为什么java,c++方法里面传参数的时候只能传对象或者基本数据类型
- 用Swing实现类似于Visio的思路
- Saro(石头) 和其他感兴趣的朋友请进,继续讨论如何将ImageIcon对象保存到本地的问题,前面的问题已经结贴,谢谢;-)
- 运行applet要下载java虚拟机?
- ajax传递数据到后台传不过去
- 如何吧class文件反编译为java文件
- 这段程序中有一句话看不懂,请帮忙解释一下。
- 文件流、缓冲流和数据流使用完后,不调用实例的close方法,系统级自动回收吗?
- 如何获取java程序当前的使用内存呢?
- SWT的重绘问题(浮动的文字)
- snmp读取交换机有多少设备在线
Display display = new Display();
Shell shell = new Shell(display); public Clipping() {
shell.setLayout(new FillLayout());
final Canvas canvas = new Canvas(shell, SWT.NULL);
final Image image = new Image(display, "java2s.gif");
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Region region = new Region();
region.add(new int[]{60, 10, 10, 100, 110, 100});
e.gc.setClipping(region);
e.gc.drawImage(image, 0, 0);
}
}); shell.setSize(200, 140);
shell.open();
//textUser.forceFocus(); // Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
} display.dispose();
} private void init() { } public static void main(String[] args) {
new Clipping();
}
}
kulatasana说的好像是AWT的方法 SWT中好像不行哦····各位大大还有别的方法吗?
public class ImagePartDraw {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Canvas Example");
shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Image image = new Image(display, "yourFile.gif");
System.out.println(image.getImageData().scanlinePad);
image.getImageData().scanlinePad = 40;
System.out.println(image.getImageData().scanlinePad); e.gc.drawImage(image, 0, 0);
// Determine how big the drawing area is
Rectangle rect = shell.getClientArea(); // Get information about the image
ImageData data = image.getImageData(); // Calculate drawing values
int srcX = data.width / 4;
int srcY = data.height / 4;
int srcWidth = data.width / 2;
int srcHeight = data.height / 2;
int destWidth = 2 * srcWidth;
int destHeight = 2 * srcHeight; // Draw the image
e.gc.drawImage(image, srcX, srcY, srcWidth, srcHeight, rect.width - destWidth, rect.height
- destHeight, destWidth, destHeight);
}
}); shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}