Add method to save a JavaFX image to file without the use of SwingFXUtils?

Scott Palmer swpalmer at gmail.com
Wed May 5 03:46:57 UTC 2021


An overhaul to ImageIO that isn’t dependent on any UI framework, but rather accesses raw image data via arrays or ByteBuffer (or even the new foreign MemoryAccess stuff?) would help. 
For specific UI framework types, BufferedImage and JavaFX Image, they just need the plumbing to get the raw data accessible to ImageIO v2.   That way we don’t need to mix different UI modules to read and write images.  There are already too many ways to read images in the JDK, it would help if they could all delegate to a single body of code.

It also might help with some cases of server-side image generation, where a full UI toolkit isn’t needed... e.g. only the JavaFX graphics module (and base) is enough to generate images.

Is anything like that every likely to happen?

Scott

> 
> On May 4, 2021, at 8:21 AM, Kevin Rushforth <kevin.rushforth at oracle.com> wrote:
> 
> Hi,
> 
> We've discussed adding image reading and writing functionality in the past. Something on the order of Java2D's Image I/O. Doing it right would be a large project, and would be more than just adding a couple methods to JavaFX Image. Unless and until we do that, using the SwingFXUtils to produce a BufferedImage from a JavaFX Image is the recommended approach.
> 
> -- Kevin
> 
> 
>> On 5/4/2021 5:08 AM, Frank Delporte wrote:
>> Hello
>> 
>> My first contribution to this mailing list... ;-)
>> 
>> During an experiment with FXGL on the Raspberry Pi + Gluon JavaFX 17-ea, it turned out there was a missing dependency to javafx.swing.
>> (also mentioned here <https://stackoverflow.com/questions/50900945/swingfxutils-alternative-for-image-serialization-javafx-swing-raspberry-pi>)
>> 
>> Turns out SwingFXUtils was used in the FXGL library only to be able to save a screenshot of the application to a file and we were able to rework it as you can see here: <https://github.com/AlmasB/FXGL/commit/737c2ba44b9c3e89ed29137ebe7f978b10ac782b>
>> 
>> I researched this topic for a few hours, but didn't manage to find a good approach to save a JavaFX Image. Maybe I missed something? Or wouldn't it be a good idea to extend the JavaFX Image or BufferedImage with e.g. writeToFile(ImageFormat.PNG), writeToFile(ImageFormat.JPG)?
>> 
>> Best regards
>> Frank Delporte
>> 
>> Want to have coding-fun?
>> Check my blog<https://webtechie.be/>and book "Getting started with Java on Raspberry Pi" on<https://webtechie.be/books/>
>> 
>> 
> 


More information about the openjfx-dev mailing list