1.SWT中截屏
很简单,可以直接用Display来做,如下:
private Image getScreenImage() {
GC gc = new GC(getDisplay());
Image image = new Image(getDisplay(), getDisplay().getBounds());
gc.copyArea(image, 0, 0);
gc.dispose();
return image;
}
可以想象display代表了整个屏,然后把它转存到一个Image上即可。
2.Swing中截屏
Swing中截屏也很简单,直接用Robot类就可以实现,如下:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage capture = new Robot().createScreenCapture(new Rectangle(
new Point(0, 0), screenSize));
3.转换
以前有篇文章讨论过,其实这两种Image之间要进行转换也是很简单的。
Swing Image到SWT Image:
BufferedImage capture = ....; //Swing Image
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(capture, "png", os);
byte[] b = os.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(b);
final Image screenImage = new Image(display, is); //SWT Image
is.close();
os.close();
SWT Image到Swing Image:
Image image = ...; //SWT Image
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[]{image.getImageData()};
imageLoader.save(os, SWT.IMAGE_PNG);
byte[] byteArray = os.toByteArray();
ImageIcon imageIcon = new ImageIcon(byteArray); //Swing Image
思路是一样的,就是通过中间存储字节流来进行转换
分享到:
相关推荐
集中了网上所有流进的C#截图方法:ffmpeg,仿QQ截图及利用类FrameGrabber截图。 本程序里已经带有ffmpeg所以也无须去网上下载。
unity三种截屏方法Demo
主要介绍了 Android截屏截图方法汇总(Activity、View、ScrollView、ListView、RecycleView、WebView截屏截图)的相关资料,需要的朋友可以参考下
暴风影音截屏方法 暴风影音怎么截图.docx
Unity3d之截图方法,希望对有需要的人有所帮助。
截图方法合集,踩过好多个坑后的场景,和方法仅供参考
flex中获取截屏方法 html文档说明 第一次上传,学习学习
10种屏幕截图方法(适合各种窗口).txt10种屏幕截图方法(适合各种窗口).txt
WINDOWS屏幕截图方法汇总.pdf
Windows中截屏方法大全
对电脑屏幕抓图,不经过第三方软件电脑屏幕截图方法。
vb6截图的两种方法(用line控件和shape控件,类似于qq截图)
Office 2021屏幕截图工具截图方法.docx
电脑截图方法.docx
电信设备-截屏方法及移动终端.zip
中间罐车设计计算截图方法分享
行业分类-设备装置-一种截屏方法
行业-电子政务-电子装置、截图方法及相关产品[4].zip
行业分类-设备装置-一种截图方法和截图工具
电信设备-截屏方法、装置和移动终端.zip