Javafx NullPointerException when rendering a large image

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.

+7
java image javafx
source share
2 answers

As someone pointed out the comments - only for textures tp 4k / 8k will work for you. This is because JavaFX probably uses a graphics processor to render images. The texture size limit is probably the limit of GPUs or yout GPUs that cannot handle large textures. It cannot create such a large texture that it returns null (and this explains the NullPointerException).

The only way to fix this is to avoid using large textures or get the best equipment to support large textures. Using software rendering (which can be very slow) can fix it by running java with the following options:

 -Dprism.order=j2d 

or

 -Dprism.order=sw 

But I'm not sure what you want to achieve.

+4
source share

I could solve this with 2 VM-Arguments:

 -Dprism.order=sw -Xmx1024m 

I needed both.

+2
source share

All Articles