2

New to JavaFX

This example works fine with small images. But a large image crashes ImageView.

Is my example code flawed? Is there a problem with large images in JavaFX? Something else?

I grab an example from the web:

http://www.java2s.com/Code/Java/JavaFX/JavaFXImageZoomExample.htm

I download and process a PDF file:

http://optics.byu.edu/BYUOpticsBook_2013.pdf

gs -sDEVICE=png16m -dNOPAUSE -dBATCH -dSAFER \
   -r600 -dFirstPage=1 -dLastPage=1 \
   -sOutputFile=001.png BYUOpticsBook_2013.pdf 

This gives me a 5100 × 6600 pixel image.

I attempt to view the image: After several seconds a window appears with an empty scrollpane and a stacktrace emitted to the console.

import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ScrollEvent;
import javafx.stage.Stage;

/**
 *
 * @author O.J. Sousa Rodrigues (office at halbgasse.at)
 */
public class ZoomExample extends Application {

  private ImageView imageView = new ImageView();
  private ScrollPane scrollPane = new ScrollPane();
  final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);

  @Override
  public void start(Stage stage) throws Exception {

    zoomProperty.addListener(new InvalidationListener() {
      @Override
      public void invalidated(Observable arg0) {
        imageView.setFitWidth(zoomProperty.get() * 4);
        imageView.setFitHeight(zoomProperty.get() * 3);
      }
    });

    scrollPane.addEventFilter(ScrollEvent.ANY,
        new EventHandler<ScrollEvent>() {

      @Override
      public void handle(ScrollEvent event) {
        if (event.getDeltaY() > 0) {
          zoomProperty.set(zoomProperty.get() * 1.1);
        } else if (event.getDeltaY() < 0) {
          zoomProperty.set(zoomProperty.get() / 1.1);
        }
      }
    });

    imageView.setImage(new Image("file:///home/jeff/001.png"));
    imageView.preserveRatioProperty().set(true);
    scrollPane.setContent(imageView);

    stage.setScene(new Scene(scrollPane, 400, 300));
    stage.show();

  }
  public static void main(String[] args) {
    launch(args);
  }
} 

The stacktrace:

java.lang.NullPointerException
at com.sun.prism.sw.SWGraphics.drawTexture(SWGraphics.java:686)
at com.sun.prism.sw.SWGraphics.drawTexture(SWGraphics.java:665)
at com.sun.prism.sw.SWGraphics.drawTexture(SWGraphics.java:648)
at com.sun.javafx.sg.prism.NGImageView.renderContent(NGImageView.java:123)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2067)
at com.sun.javafx.sg.prism.NGImageView.doRender(NGImageView.java:103)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1959)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:576)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2067)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1959)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:576)
at com.sun.javafx.sg.prism.NGNode.renderForClip(NGNode.java:2308)
at com.sun.javafx.sg.prism.NGNode.renderRectClip(NGNode.java:2202)
at com.sun.javafx.sg.prism.NGNode.renderClip(NGNode.java:2228)
at com.sun.javafx.sg.prism.CacheFilter.impl_renderNodeToCache(CacheFilter.java:663)
at com.sun.javafx.sg.prism.CacheFilter.render(CacheFilter.java:567)
at com.sun.javafx.sg.prism.NGNode.renderCached(NGNode.java:2372)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2058)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1959)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:576)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2067)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1959)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:474)
at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:327)
at com.sun.javafx.tk.quantum.UploadingPainter.run(UploadingPainter.java:135)
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:125)
at java.lang.Thread.run(Thread.java:745) 

1 Answers1

3

There are several bugs reported on Jira (you need to be registered to read them):

  • RT-21998 NullPointerException when rendering image
  • RT-22669 Need to handle the case of a failed texture load when rendering large images
  • RT-22073 Exception thrown from snapshot if dimensions are larger than max texture size ...

Enable this option -Dprism.verbose=true to check your settings.

Also, following this link, there's an option to set the video memory. Try "-Dprism.poolstats=true" to monitor the actual usage of the texture pool to better determine the upper limit, and set "-Dprism.maxvram=XX" with that limit (XX=500m, ...)

I haven't tested this, though. Could you post a link to your image?

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thank you José. I am off to work at this moment. I will follow the links you provide and your suggestions. I don't know of a good place to post an image. If you saw my previous post I hope you did not follow the link I provided. My image may be reproduced by using the link and ghostscript command I provided in my original post. – user4250202 Jan 08 '15 at 15:37
  • the kenai site links are broken, probably correct ones are: https://bugs.openjdk.java.net/browse/JDK-8117239 https://bugs.openjdk.java.net/browse/JDK-8089112 https://bugs.openjdk.java.net/browse/JDK-8088198 also see https://bugs.openjdk.java.net/browse/JDK-8090822 – George Birbilis May 10 '17 at 08:37