演示了如何利用图像 : 图像 « SWT-JFace-Eclipse « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » SWT-JFace-Eclipse » 图像屏幕截图 
演示了如何利用图像
演示了如何利用图像


//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates how to draw images
 */
public class DrawImagesDemo {
  public void run() {
    Display display = new Display();
    final Shell shell = new Shell(display);

    // Load an image
    final Image image = new Image(display, this.getClass().getResourceAsStream(
        "java2s.gif"));
    System.out.println(image.getImageData().scanlinePad);
    image.getImageData().scanlinePad = 40;
    System.out.println(image.getImageData().scanlinePad);

    shell.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent event) {
        // Draw the untainted image
        event.gc.drawImage(image, 00);

        // 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 = * srcWidth;
        int destHeight = * srcHeight;

        // Draw the image
        event.gc.drawImage(image, srcX, srcY, srcWidth, srcHeight, rect.width
            - destWidth, rect.height - destHeight, destWidth, destHeight);
      }
    });
    shell.setText("Draw Images");
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    image.dispose();
    display.dispose();
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new DrawImagesDemo().run();
  }
}


           
       
Related examples in the same category
1. 图像分析仪SWT图像分析仪SWT
2. 设置图标与不同的分辨率设置图标与不同的分辨率
3. 捕获工具图像与GC捕获工具图像与GC
4. 创建一个图标(在内存中)创建一个图标(在内存中)
5. 显示动画GIF显示动画GIF
6. 旋转和翻转图像旋转和翻转图像
7. 显示图像组显示图像组
8. SWT和图像
9. 绘制图像为例绘制图像为例
10. 剪辑图片剪辑图片
11. 双缓冲双缓冲
12. 图像基础图像基础
13. 文件图标工具
14. 滚动图片(闪烁,没有双缓冲)滚动图片(闪烁,没有双缓冲)
15. 传输型转移SWT ImageData对象。
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.