首页 > 编程 > Java > 正文

java使用swt显示图片示例分享

2019-11-26 15:40:52
字体:
来源:转载
供稿:网友

复制代码 代码如下:

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class ImagesHelloWorld {

 public static void main(String[] args) {
  Display display = Display.getDefault();
  Shell shell = new Shell();
  Image image = new Image(display, "c://c240b2dcc132c9c6.jpg");
  shell.setText("ImageReader");
  shell.setImage(image);
  Rectangle bounds = image.getBounds();
  shell.setSize(bounds.width + 15, bounds.height +15);
  shell.open();
  GC gc = new GC(shell);
  gc.drawImage(image,5,5);
  shell.layout();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch()) {
    display.sleep();
   }
  }
  display.dispose();
 }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表