Reputation: 2764
I'm making a raster image editor in JavaFX, and all the imaging libraries I've found use BufferedImage
. Problem is, I can't display a BufferedImage
in a JavaFX app, without converting it to javafx.scene.image.Image
first. I'm concerened about speed here; if I'm constantly converting between BufferedImage
and JavaFX's Image
, the UI will lag.
For example, if the user wants to draw a line with the pencil tool, I'm constantly updating the image in the UI. Every time they move the cursor, I have to convert between BufferedImage
and JavaFX's Image
, which I'm sure will make the line appear laggy as it's being drawn.
The libraries I've found are ImgLib2, Marvin, Apache Commons Imaging Library, and ImageJ. All of them use BufferedImage
. I haven't found an imaging library yet that uses JavaFX
's Image
.
So my question is: how do I display a BufferedImage
directly in JavaFX? I'm reluctant to go back to AWT. Alternatively, is there an imaging library that uses JavaFX's Image
instead of BufferedImage
?
Thanks for your replies!
Upvotes: 0
Views: 2152
Reputation: 159290
Use a SwingNode to display a BufferedImage in JavaFX without first converting the image to a JavaFX Image.
I do not know if this would be any more performant than doing an image conversion, you would have to do some benchmarking with your application to see.
In general, I'd probably recommend doing a conversion over putting a BufferedImage in a SwingNode. With a SwingNode you will need to be careful how you manage threading and I think benchmarking using a SwingNode will not yield you the performance increase you are looking for.
Upvotes: 1