Reputation: 634
I'm trying to render a .png Image using the GraphicsContext.drawImage(...)
method under JavaFX 8. My code works perfectly fine for an image of size ~1000px x 2000px.
But unfortunately I need to render an image of size 7000px x 14000px. Loading this image works fine as well, but when calling the drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight())
method 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)
It doesn't make a difference if I try to resize the image while drawing to the canvas or if I try to render the whole image.
My guess is that the image size is simply too big to render, but I could'nt find any source to validate this and neither could I find anything to solve my problem.
I also made an analysis of the Java heap (with Eclipse Memory Analyzer) which showed an image size of approximately 376 MB.
So basically my question are: 1. Why is my program crashing? Is it because the image is too big? 2. If my image is too big, how can I increase the available space for Java? My machine has 8GB RAM and the graphics card has 1GB RAM, so an image of <400MB should not really be a problem.
Upvotes: 12
Views: 4796
Reputation: 1
I solved it for me with VM-Arguments:
-Dprism.poolstats=true
-Dprism.maxvram=500m
-Dprism.order=sw
-Djavafx.animation.fullspeed=true
Upvotes: 0
Reputation: 31
I could solve it with the 2 VM-Arguments:
-Dprism.order=sw
-Xmx1024m
I needed both of them.
Upvotes: 3
Reputation: 1355
As somebody pointed in comments - only up tp 4k/8k textures will work for you. This is because JavaFX probably uses GPU to render images. Texture size limit is probably the limit of yout GPU or GPU drivers that can't handle bigger textures. It can't create so big texture so it returns null (and that explains the NullPointerException).
The only way to fix it is to avoid using so big textures or get better hardware to support bigger textures. Using software rendering (which may be really slow) may fix it by running java with the following parameters:
-Dprism.order=j2d
or
-Dprism.order=sw
But I'm not sure it's what you want to achieve.
Upvotes: 8