It isn't difficult to write a utility method to convert a non-animated <tt>java.awt.Image</tt> to <tt>javafx.scene.image.Image</tt>. But short of using <tt>Robot</tt> to obtain a screenshot (and hope that no part of the fx Image is obscured) is there a way to do the reverse? And is there a way to convert an
animated <tt>java.awt.Image</tt> to <tt>javafx.scene.image.Image</tt>?
public static javafx.scene.image.Image createImage(java.awt.Image image) throws IOException {
if (!(image instanceof RenderedImage)) {
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
image = bufferedImage;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write((RenderedImage) image, "png", out);
out.flush();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
return new javafx.scene.image.Image(in);
}
Any inputs are appreciated.
db