Closed Ali-RS closed 1 year ago
That's because it's in linear light unless you transform it. You have to call decode.transform(ColorFlags.PRI_SRGB, ColorFlags.WP_D65, ColorFlags.TF_SRGB, JXLOptions.PEAK_DETECT_AUTO)
before ImageIO will accept it. Alternatively, you could just draw it onto another BufferedImage.
You have to call decode.transform(ColorFlags.PRI_SRGB, ColorFlags.WP_D65, ColorFlags.TF_SRGB, JXLOptions.PEAK_DETECT_AUTO)
I added this before calling asBufferedImage
but still not exporting. Calling ImageIO.write(image, "png", file); still returns false.
try {
JXLDecoder decoder = new JXLDecoder("samples/bench.jxl");
JXLImage jxlImage = decoder.decode();
jxlImage = jxlImage.transform(ColorFlags.PRI_SRGB, ColorFlags.WP_D65, ColorFlags.TF_SRGB, JXLOptions.PEAK_DETECT_AUTO);
BufferedImage image = jxlImage.asBufferedImage();
File file = new File("bench.png");
System.out.println("Output=" + file.getAbsolutePath());
try {
boolean write = ImageIO.write(image, "png", file);
if (!write) {
System.err.println("Could not write image.");
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
The PNG writer also doesn't support float output, so you'll need a BufferedImage that isn't TYPE_FLOAT.
In either case, ImageIO doesn't write the sRGB
chunk so you're better off using PNGWriter, which jxlatte provides.
I can not write the BufferedImage returned by
XLImage.asBufferedImage()
usingImageIO.write()
Calling
ImageIO.write(image, "png", file);
returns false. No exception is thrown.