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


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();
 }
}

若文章对您有帮助,帮忙点个赞!

0
2
发布时间 2014-02-21 11:43:06
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)