---
title: " robot.createScreenCapture(this.screenBounds);"
author: "xiaguangme"
date: "2012-08-13T07:45:16Z"
tags: []
categories: ["编程语言"]
slug: "robot-createscreencapture-this-screenbounds"
draft: false
lastmod: "2012-08-13T07:45:16Z"
id: 1629959
url: "https://simoncook.iteye.com/blog/1629959"
---

Java code

```
import com.sun.image.codec.jpeg.*;

    public static byte[] getCompressedImageAWT(BufferedImage image) {
        byte[] imageData = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
            encoder.encode(image);
            imageData = baos.toByteArray();
        } catch (IOException

 ex) {
            ex.printStackTrace();
        }
        return imageData;
    }


BufferedImage capturedImage = robot.createScreenCapture(this.screenBounds);
```