I am trying to render a .png image using the GraphicsContext.drawImage(...) method in JavaFX 8. My code works fine for an image of ~ 1000 pixels x 2000 pixels in size. But, unfortunately, I need to make an image of 7000px x 14000px size. Downloading this image is also fine, but when I call drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight()) I get the following error output:
java.lang.NullPointerException at com.sun.prism.impl.BaseGraphics.drawTexture(BaseGraphics.java:389) at com.sun.prism.impl.ps.BaseShaderGraphics.drawTexture(BaseShaderGraphics.java:139) at com.sun.javafx.sg.prism.NGCanvas.handleRenderOp(NGCanvas.java:1228) at com.sun.javafx.sg.prism.NGCanvas.renderStream(NGCanvas.java:997) at com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:578) ... more rendering stuff here at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043) at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951) at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:469) at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:317) at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:89) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:129) at java.lang.Thread.run(Thread.java:745)
I canβt resize the image when drawing to canvas or if I try to display the entire image.
I assume that the image size is too large for rendering, but I cannot find a source to verify this, nor can I find anything to solve my problem.
I also did a Java heap analysis (with Eclipse Memory Analyzer) which showed an image size of approximately 376 MB.
So basically my question is: 1. Why is my program crashing? Is it because the image is too large? 2. If my image is too large, how can I increase the available space for Java? My machine has 8 GB of RAM, and the graphics card has 1 GB of RAM, so an image <400 MB should not be a problem.
java image javafx
schauk11erd
source share