0

I'm trying get screenshot of choosen area of screen. Screen I mean desktop with opened folders, browsers etc.. The problem is everything is outside java program windows, and it shoud be like that. I'm adding screen to explain you better.

View of the screen

And result Result of screening

How it should be done? By other scene that I will put in the region and resize it and get what's under it? Or maybe is here something easier to use?

  • 1
    Try `createScreenCapture()` in a mouse drag handler; here's a related Swing [example](https://stackoverflow.com/a/3742841/230513). – trashgod Jun 26 '19 at 16:59

1 Answers1

1

If I understood it right you want to make a screenshot of a certain area of the Desktop so you have first take a screenshot:

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);

Then I would just crop it with this:

BufferedImage croppedImage = capture.getSubimage(x, y, width, height);

I hope this helps you :)

fuggerjaki61
  • 822
  • 1
  • 11
  • 24
  • The rectangle takes in width and height as well as a x and y coordinate, meaning that you could create a rectangle to be the size of the image you want and then give it the correct x and y screen coordinates to capture the area you're interested in. No need to crop the image then, though it could, of course, be useful to know of that functionality. – Robert Jun 26 '19 at 20:39
  • Exacly what I'm trying to do, but the problem is how to do screenshot only in specific cordinates, specified by some kind of field (rubberband) or as you said rectangle. Maybe somebody knows libraries or code with will help to execute this problem. – LolenFromPolen Jun 27 '19 at 08:17
  • @LolenFromPolen: The host window system typically owns such gestures; instead, focus on controlling the capture bounds in your application's interface; for example, start with a stage-sized piece surrounding the screen's center, and drag to pan the selection. – trashgod Jun 27 '19 at 16:33