在RFT中如何截取屏幕图像并保存到文件中?
来源:互联网 发布:电气工程软件 编辑:程序博客网 时间:2024/05/17 18:23
在RFT中,如何截取屏幕图像并保存到文件中?下面的脚本实现了3种类型的图像截取,包括截取整个屏幕的图像、截取指定区域的图像、截取某个测试对象的图像:
public void testMain(Object[] args)
{
// TODO 在此插入代码
captureScreen("C://temp1.jpg");
captureScreen("C://temp2.jpg",100,100,100,100);
startApp("calc");
计算器window().waitForExistence();
计算器window().activate();
captureScreen("C://temp3.jpg",(TestObject)计算器window());
}
截取整个屏幕的图像:
public static void captureScreen(String filename)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = screenSize.width;
int height = screenSize.height;
doScreenCapture(filename, 0, 0, width, height);
}
截取指定的区域图像:
public static void captureScreen(String filename, int x, int y, int width, int height)
{
doScreenCapture (filename, x, y, width, height);
}
截取指定测试对象的图像:
public static void captureScreen(String filename, TestObject to)
{
Rectangle r = null;
//html
if (to.getProperties().containsKey(".bounds"))
r = (Rectangle)to.getProperty(".bounds");
//win
else if (to.getProperties().containsKey(".screenRectangle"))
r = (Rectangle)to.getProperty(".screenRectangle");
//swing
else if (to.getProperties().containsKey("bounds"))
{
r = (Rectangle)to.getProperty("bounds");
java.awt.Point point = null;
if (to.getProperties().containsKey("location")) //swt
point = (Point)to.getProperty("location");
else
point = (Point)to.getProperty("locationOnScreen");
if (point != null)
r.setLocation(point);
}
else
{
System.out.println("Error in captureScreen: could not capture test object");
return;
}
doScreenCapture(filename, r.x, r.y, r.width, r.height);
}
protected static void doScreenCapture (String filename, int x, int y, int width, int height)
{
try {
BufferedImage capture = null;
Rectangle area = new Rectangle(x, y, width, height);
Robot robot = new Robot();
capture = robot.createScreenCapture(area);
FileOutputStream out =
new FileOutputStream(filename);
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(out);
encoder.encode(capture);
out.flush();
out.close();
}
catch (Exception e) {
System.out.println("Error in BitmapOps#doScreen: error capturing image: " + e);
}
}
}
- 在RFT中如何截取屏幕图像并保存到文件中?
- 如何在VB中执行屏幕捕捉并保存到指定位置
- C# 截取屏幕图像并保存
- 从图像中截取一块并作为图像保存--OpenCV
- 截取手机屏幕中某个View的图像,并以图片形式保存到本地相册
- 如何捕捉图像并保存在文件夹中
- lazarus中截取整个屏幕画面并保存为指定文件
- IOS中截取当前屏幕,并保存图片
- IOS中截取当前屏幕,并保存图片
- IOS中截取当前屏幕,并保存图片
- android 截取当前屏幕保存到sd卡中
- 将屏幕截取并保存为文件
- 如何在RFT中比较两个图像文件?
- 在RFT中添加文件检查点
- 在Qt中如何加载图像以及保存图像到数据库中
- 截屏,并将截取的图片保存到相册中
- 保存HBITMAP图像到文件中
- ios-day15-04(Quartz 2D之屏幕截图、并将截图保存到文件中)
- [转]struct的初始化,拷贝及指针成员的使用技巧
- javascript中利用数组实现的循环队列
- WinCE下自定义Shell的方法
- C#有向图拓扑排序
- java调用mysql的工具类实现数据库远程备份,还原,生成创建表的sql脚本
- 在RFT中如何截取屏幕图像并保存到文件中?
- Ibatis中如何读取sqlMapConfig.xml文件
- 通过value传递对象的引用
- 【转】C语言之详解#ifdef、宏等妙用
- SONY CR13 实战 windows7
- 结合PHP使用HTML表单访问单个和多个表单值
- 典型的中断服务程序
- 谷歌笑话
- 北京周边骑行路线