5

When taking a screenshot of my scene in JavaFx, I save the BufferedImage to a file as a PNG/JPG. When I try to maximize the image size to its full length, I get Black borders on the picture from the left of the image to the bottom without the image increasing its size at all. The size of the image only increases until I set my dimensions to 1300x700 as shown below.

 BufferedImage image = new BufferedImage(1300, 700, BufferedImage.TYPE_INT_RGB); 

However once I increase the dimensions greater than 1300x700, the black borders appear.

The following picture is set to

  BufferedImage image = new BufferedImage(1500, 900, BufferedImage.TYPE_INT_RGB); 

enter image description here

As you can see, part of the image is still cut off and there is now a big black border next to the image rather than the actual full sized image.

The following picture is set to

  BufferedImage image = new BufferedImage(1300, 700, BufferedImage.TYPE_INT_RGB); 

enter image description here

As you can see, the image is still cut off at the same spot as before but there is no black border along side with it.

How can I fit the whole snapshot of my current scene into one file without these borders and without any of the content getting cut off?

Here is my code:

    File fa = new File("test.jpg");
    snapshot = quotes.getScene().snapshot(null);

    RenderedImage renderedImage = SwingFXUtils.fromFXImage(snapshot, null);
    BufferedImage image = new BufferedImage(1300, 700, BufferedImage.TYPE_INT_RGB); 
    image.setData(renderedImage.getData());
    ImageIO.write(image, "jpg", fa);
Morelka
  • 177
  • 4
  • 16
  • Try to set WritableImage as parameter for snapshot method, something like this: `quotes.getScene().snapshot(snapshot);` – Eeliya Aug 11 '13 at 23:48

1 Answers1

0

The black border comes from uninitialized pixel buffer, inside your BufferedImage object. So, I guess the renderedImage itself does not contains the right part of your scene.

The scene may not yet be properly resized when you are taking the snapshot. Try to give an appropriate WritableImage to the snapshot method:

snapshot = quotes.getScene().snapshot(new WritableImage(1500, 900));
Guillaume Poussel
  • 9,572
  • 2
  • 33
  • 42