当前位置: 首页>>代码示例>>Java>>正文


Java Robot.createScreenCapture方法代码示例

本文整理汇总了Java中java.awt.Robot.createScreenCapture方法的典型用法代码示例。如果您正苦于以下问题:Java Robot.createScreenCapture方法的具体用法?Java Robot.createScreenCapture怎么用?Java Robot.createScreenCapture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Robot的用法示例。


在下文中一共展示了Robot.createScreenCapture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: captureImage

import java.awt.Robot; //导入方法依赖的package包/类
public static BufferedImage captureImage(String iii) {
    try {
        Rectangle rec = new Rectangle(CAPTURE_1_X, CAPTURE_1_Y, CAPTURE_2_X, CAPTURE_2_Y);
        Robot robot = new Robot();
        
        BufferedImage img = robot.createScreenCapture(rec);
        
        int[] rawData = new int[DesktopScreenRecorder.FRAME_SIZE];

        img.getRGB(0, 0,
                DesktopScreenRecorder.CAPTURE_2_X,
                DesktopScreenRecorder.CAPTURE_2_Y,
                rawData,
                0,
                DesktopScreenRecorder.CAPTURE_2_X);
        
        return img;
    } catch (Exception e) {
        UIUtils.popupError(e, "ImageUtils::writeImage");
    }
    return null;
}
 
开发者ID:mhusam,项目名称:ChessBot,代码行数:23,代码来源:ImageUtils.java

示例2: ScreenCut

import java.awt.Robot; //导入方法依赖的package包/类
/**
 * Creates new form ScreenCut
 *
 * @param parent
 * @param modal
 */
public ScreenCut(java.awt.Frame parent, boolean modal) {
    initComponents();
    addMouseListener(this);
    addMouseMotionListener(this);
    toolbar.setVisible(false);
    panel.setVisible(false);
    text.setVisible(false);
    try {
        robot = new Robot();
        screen = new Rectangle(tool.getScreenSize());
        setSize(screen.width, screen.height);
        bgimg = robot.createScreenCapture(screen);
        cur = tool.createCustomCursor(tool.createImage(getClass().getResource("/cur.png")), new Point(0, 0), "cur");
        setCursor(cur);
        ButtonGroup bg = new ButtonGroup();
        bg.add(size1);
        bg.add(size2);
        bg.add(size3);
        initActionListener(panel.getComponents());
        initActionListener(toolbar.getComponents());
    } catch (AWTException ex) {
        Logger.getLogger(ScreenCut.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:ajtdnyy,项目名称:ScreenCut,代码行数:31,代码来源:ScreenCut.java

示例3: checkOK

import java.awt.Robot; //导入方法依赖的package包/类
/**
 * This method checks a squared radius of 10 px around the Point and compares the screen color with the color of the ok-button, that ends an game. 
 * @param p the point to scann
 * @param bot the Robot object to use
 * @return true, if there are more then 70px alike enough
 */
private boolean checkOK(Point p, Robot bot, Color goalcolor) {
	if(p == null | bot == null | goalcolor == null)
		return false;
	//long start = System.currentTimeMillis();
	int count = 0;
	BufferedImage img = bot.createScreenCapture(getRect(p.x, p.y));//smile
	for (int x = 0; x < img.getWidth(); x++) {
		for (int y = 0; y < img.getHeight(); y++) {
			int color = img.getRGB(x, y);
			int red = (color & 0x00ff0000) >> 16;
			int green = (color & 0x0000ff00) >> 8;
			int blue = color & 0x000000ff;
			double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2)
			+ Math.pow((red - goalcolor.getRed()), 2) + Math.pow((green - goalcolor.getGreen()), 2));//calculate the distance between the goalcolor and the test color
			if (distance < mincolordistance)
				count++;
		}
	}

	System.out.println("counts: " + count);//some performance checking
	return count > 4;//engough pixel have the right color
}
 
开发者ID:mrbesen,项目名称:ClashRoyale-Bot,代码行数:29,代码来源:Clicker.java

示例4: capture

import java.awt.Robot; //导入方法依赖的package包/类
public static File capture() {
    try {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        Robot rt = new Robot();
        BufferedImage img = rt.createScreenCapture(
                new Rectangle(DesktopScreenRecorder.CAPTURE_1_X, 
                        DesktopScreenRecorder.CAPTURE_1_Y, 
                        DesktopScreenRecorder.CAPTURE_2_X, 
                        DesktopScreenRecorder.CAPTURE_2_Y));
        
        File imageFile = new File("find-move-"+String.format("%2d", COUNTER)+"-cap.jpeg");
        COUNTER++;
        if (ImageIO.write(img, "jpeg", imageFile)) {
            return imageFile;
        }
    } catch (Exception e) {
        UIUtils.popupError(e, "ImageUtils::capture");
    }
    return null;
}
 
开发者ID:mhusam,项目名称:ChessBot,代码行数:21,代码来源:ImageUtils.java

示例5: main

import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(20);
        SwingUtilities.invokeAndWait(JInternalFrameDraggingTest::createAndShowGUI);
        robot.waitForIdle();

        final int translate = FRAME_SIZE / 4;
        moveFrame(robot, translate, translate / 2, translate / 2);
        robot.waitForIdle();

        Point p = getDesktopPaneLocation();
        int size = translate / 2;
        Rectangle rect = new Rectangle(p.x, p.y, size, size);
        BufferedImage img = robot.createScreenCapture(rect);

        int testRGB = BACKGROUND_COLOR.getRGB();
        for (int i = 0; i < size; i++) {
            int rgbCW = img.getRGB(i, size / 2);
            int rgbCH = img.getRGB(size / 2, i);
            if (rgbCW != testRGB || rgbCH != testRGB) {
                throw new RuntimeException("Background color is wrong!");
            }
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:JInternalFrameDraggingTest.java

示例6: TakeScreenshot

import java.awt.Robot; //导入方法依赖的package包/类
public static void TakeScreenshot(String filePath, String fileName) {
    try {
        Robot robot = new Robot();
        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
        ImageIO.write(screenFullImage, "jpg", new File(filePath + fileName + ".jpg"));
    } catch (AWTException | IOException ex) {
        System.out.println(ex.getMessage());
    }
}
 
开发者ID:tiagorlampert,项目名称:sAINT,代码行数:11,代码来源:Screenshot.java

示例7: snapshot

import java.awt.Robot; //导入方法依赖的package包/类
public void snapshot()
{
	try
	{
		Robot robot = new Robot();
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		image = robot.createScreenCapture(new Rectangle(0, 0, d.width,
				d.height));
	}
	catch (AWTException e)
	{

	}
}
 
开发者ID:sxei,项目名称:myqq,代码行数:15,代码来源:ScreenFram.java

示例8: printScreen

import java.awt.Robot; //导入方法依赖的package包/类
/**
 * Salva uma imagem .png com o printscreen da tela atual
 *
 * @param file local a ser salva a imagem
 * @return {@code true} para imagem salva. {@code false} para erro ao salvar
 * imagem.
 */
public static boolean printScreen(File file) {
    try {
        Robot robot = new Robot();
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension d = toolkit.getScreenSize();
        BufferedImage bi = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
        ImageIO.write(bi, "PNG", file);
        return true;
    } catch (Exception ex) {
        return false;
    }
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:20,代码来源:Img.java

示例9: showFrame

import java.awt.Robot; //导入方法依赖的package包/类
private static void showFrame() throws Exception {
    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    createUI();
    images[step] = robot.createScreenCapture(bounds);
    SwingUtilities.invokeAndWait(frame::dispose);
    sleep();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:NSTexturedJFrame.java

示例10: getFullScreenShot

import java.awt.Robot; //导入方法依赖的package包/类
/**全屏截图*/
private void getFullScreenShot() throws Exception{
	Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	Robot robot = new Robot();
	screenImg = robot.createScreenCapture(new Rectangle(d.width, d.height));
	screenImgRGBData = getImageGRB(screenImg);
	screenImgWidth = screenImg.getWidth();
	screenImgHeight = screenImg.getHeight();
	/*try {
		ImageIO.write(screenImg, "jpg", new File("E:/IMG/test/"+System.currentTimeMillis()+".jpg"));
	} catch (IOException e) {
		e.printStackTrace();
	}*/
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:15,代码来源:ImageCognition.java

示例11: robotScreenCapture

import java.awt.Robot; //导入方法依赖的package包/类
public void robotScreenCapture(String robotImageName) throws Exception 
{
	re = new Robot();
	Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
	BufferedImage bufferedImage = re.createScreenCapture(area);
	// Save as PNG
	File file = new File(robotImageName);
	if (file.exists()) {
		file.delete();
	}
	ImageIO.write(bufferedImage, "png", file);
}
 
开发者ID:GladsonAntony,项目名称:WebAutomation_AllureParallel,代码行数:13,代码来源:BaseMethod.java

示例12: takeAShot

import java.awt.Robot; //导入方法依赖的package包/类
public static BufferedImage takeAShot() throws AWTException, IOException {
    Robot robot = new Robot();
    Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage output = robot.createScreenCapture(screenRect);
    return output;
}
 
开发者ID:flschiavoni,项目名称:shareMySheet,代码行数:7,代码来源:ScreenShot.java

示例13: main

import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws AWTException
{
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    if (gds.length < 2) {
        System.out.println("It's a multiscreen test... skipping!");
        return;
    }

    for (int i = 0; i < gds.length; ++i) {
        GraphicsDevice gd = gds[i];
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        Rectangle screen = gc.getBounds();
        Robot robot = new Robot(gd);

        // check Robot.mouseMove()
        robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
        Point mouse = MouseInfo.getPointerInfo().getLocation();
        Point point = screen.getLocation();
        point.translate(mouseOffset.x, mouseOffset.y);
        if (!point.equals(mouse)) {
            throw new RuntimeException(getErrorText("Robot.mouseMove", i));
        }

        // check Robot.getPixelColor()
        Frame frame = new Frame(gc);
        frame.setUndecorated(true);
        frame.setSize(100, 100);
        frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
        frame.setBackground(color);
        frame.setVisible(true);
        robot.waitForIdle();
        Rectangle bounds = frame.getBounds();
        if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
            throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
        }

        // check Robot.createScreenCapture()
        BufferedImage image = robot.createScreenCapture(bounds);
        int rgb = color.getRGB();
        if (image.getRGB(0, 0) != rgb
            || image.getRGB(image.getWidth() - 1, 0) != rgb
            || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
            || image.getRGB(0, image.getHeight() - 1) != rgb) {
                throw new RuntimeException(
                        getErrorText("Robot.createScreenCapture", i));
        }
        frame.dispose();
    }

    System.out.println("Test PASSED!");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:53,代码来源:MultiScreenLocationTest.java

示例14: doCapture

import java.awt.Robot; //导入方法依赖的package包/类
private static void doCapture(Component test) {
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    // Grab the screen region
    try {
        Robot robot = new Robot();
        Point pt1 = test.getLocationOnScreen();
        Rectangle rect =
            new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
        capture = robot.createScreenCapture(rect);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:DrawImageBilinear.java

示例15: capture

import java.awt.Robot; //导入方法依赖的package包/类
public static BufferedImage capture(Robot rob, ComponentOperator operator) {
    Rectangle boundary = new Rectangle(operator.getLocationOnScreen(),
            operator.getSize());
    return rob.createScreenCapture(boundary);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JemmyExt.java


注:本文中的java.awt.Robot.createScreenCapture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。