Effective image cropping in JavaFX

前端 未结 2 852
甜味超标
甜味超标 2020-12-11 05:29

I\'m trying to write a Jigsaw puzzle using JavaFX partly because someone asked me and partly because I want to give JavaFX a go. However, I am having difficulty with the ac

相关标签:
2条回答
  • 2020-12-11 06:01

    Multiple ImageView objects can reference the same Image. The data for the image itself is stored in the Image. If you have 1000 ImageView objects each referencing the same Image then there is only 1 copy of the pixels in memory. Creating copies using WriteableImage would actually be more expensive than having multiple ImageView objects.

    0 讨论(0)
  • 2020-12-11 06:08

    Using PixelReader and WritableImage should help.

    the following cuts a new image from an old one at position (x,y) and size (width, height)

    PixelReader reader = oldImage.getPixelReader();
    WritableImage newImage = new WritableImage(reader, x, y, width, height);
    
    0 讨论(0)
提交回复
热议问题