On Thu, 20 Aug 2026 17:14:56 GMT, Andy Goryachev <[email protected]> wrote:

>> Any internal code that needs to read/write javafx images currently goes 
>> through the `ImageIO` (`java.desktop` module) and the `SwingFXUtils` (in 
>> `javafx.swing` module).
>> 
>> To avoid adding dependencies, we should move the bulk of implementation to 
>> the `javafx.graphics` module which in turn can be used by the `SwingFXUtils` 
>> and other internal code without adding additional explicit dependencies.
>> 
>> This PR moves the `SwingFXUtils` implementation to 
>> javafx.graphics/com.sun.javafx.util.ImageUtils and also adds a utility method
>> 
>> public static byte[] writeImage(Image im, String format) throws IOException
>> 
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Andy Goryachev has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   unused imports

modules/javafx.graphics/src/main/java/com/sun/javafx/util/ImageUtils.java line 
179:

> 177: 
> 178:     /**
> 179:      * Determine the appropriate {@link WritablePixelFormat} type that 
> can

SInce you changed to "Determines" in above javadoc, we can do the same here too

modules/javafx.graphics/src/main/java/com/sun/javafx/util/ImageUtils.java line 
323:

> 321:             ImageIO.setUseCache(false);
> 322:             try {
> 323:                 BufferedImage bi = fromFXImage(im, null);

fromFXImage can return null too, guess null check is required so that it doesnt 
throw IllegalArumentException or maybe update javadoc to ensure user knows 
about it

modules/javafx.graphics/src/main/java/com/sun/javafx/util/ImageUtils.java line 
328:

> 326:                 ImageIO.setUseCache(old);
> 327:             }
> 328:             return out.toByteArray();

`ImageIO.write` can return false as we saw for the issue where JPEG writer is 
not found for alpha-present-BI so I guess we should attempt writing to output 
stream only if it returns true else throw IOException
since the javadoc says "returns the byte array"

modules/jfx.incubator.richtext/src/main/java/module-info.java line 40:

> 38:     requires transitive javafx.controls;
> 39:     requires transitive jfx.incubator.input;
> 40:     requires java.desktop;

Is this now required in modules/javafx.swing/src/main/java/module-info.java


   exports com.sun.javafx.embed.swing to
        javafx.graphics;

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2267#discussion_r3827385447
PR Review Comment: https://git.openjdk.org/jfx/pull/2267#discussion_r3827416529
PR Review Comment: https://git.openjdk.org/jfx/pull/2267#discussion_r3827457768
PR Review Comment: https://git.openjdk.org/jfx/pull/2267#discussion_r3827479375

Reply via email to