java使用swt显示图片示例分享
程序员文章站
2024-02-24 22:21:43
复制代码 代码如下:import org.eclipse.swt.graphics.gc;import org.eclipse.swt.graphics.image;imp...
复制代码 代码如下:
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();
}
}
上一篇: 数组与字符串
下一篇: java实现上传图片并压缩图片大小功能