Effective cropping images in JavaFX

I am trying to write a puzzle using JavaFX partly because someone asked me and partly because I want to give JavaFX. However, I am having difficulty actually cropping the image.

The idea is for the user to provide an image and a program to cut the image into smaller parts. Simple, right? My problem is this: the only way to find the image is to make a copy of the image object and change the visible part of the copy, here is an example:

ImageView imgageView = new ImageView(); // Creates a new ImageView; this will be a single puzzle piece.
imgageView.setImage(originalImage); // Use the original image as the "base."
Rectangle2D rectangle = new Rectangle2D(0, 0, 50, 50); // Crop the image from (0,0) to (50, 50).

To clarify the last line, here is the related element in the API :

public Rectangle2D(double minX,
           double minY,
           double width,
           double height)
Creates a new instance of Rectangle2D.
Parameters:
minX - The x coordinate of the upper-left corner of the Rectangle2D
minY - The y coordinate of the upper-left corner of the Rectangle2D
width - The width of the Rectangle2D
height - The height of the Rectangle2D

, ( ), , 1200 ? ? , . , , , "".

? , , ?

+5
2

PixelReader WritableImage .

position (x,y) size (width, height)

PixelReader reader = oldImage.getPixelReader();
WritableImage newImage = new WritableImage(reader, x, y, width, height);
+11

ImageView . . 1000 ImageView, , 1 . WriteableImage , ImageView.

+9

All Articles