package imagetest; import com.sun.javafx.iio.ImageFrame; import com.sun.javafx.iio.ImageStorage; import com.sun.prism.GraphicsPipeline; import com.sun.prism.ImageFormatTool; import com.sun.prism.Texture; import com.sun.prism.j2d.J2DTexture; import java.awt.Canvas; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javafx.application.Application; import javafx.stage.Stage; public class BmpLoadTest extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws IOException { //InputStream is = new TestInputStream(new FileInputStream("cross.png")); //InputStream is = new FileInputStream("cross.bmp"); InputStream is = new TestInputStream(new FileInputStream("cross.bmp")); ImageFrame[] frames = ImageStorage.loadAll(is, null, 0, 0, true, false); com.sun.prism.Image prismImage = ImageFormatTool.convertImageFrame(frames[0]); Texture texture = GraphicsPipeline.getDefaultResourceFactory() .createTexture(prismImage); java.awt.Image awtImage = ((J2DTexture) texture).getBufferedImage(); final Frame f = new Frame(); f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); f.add(new ImageCanvas(awtImage)); f.pack(); f.setVisible(true); } private static class TestInputStream extends InputStream { private final InputStream delegate; public TestInputStream(InputStream delegate) { this.delegate = delegate; } @Override public int read() throws IOException { return delegate.read(); } @Override public int read(byte[] b, int off, int len) throws IOException { return delegate.read(b, off, Math.min(len, 128)); } } private static class ImageCanvas extends Canvas { java.awt.Image image; public ImageCanvas(java.awt.Image image) { this.image = image; } @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } @Override public void paint(Graphics g) { g.drawImage(image, 0, 0, null); } } }