Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30656 > unrolled thread

JavaFX large image crashes ImageView

Started byJeff Higgins <jeff@invalid.invalid>
First post2015-01-07 20:32 -0500
Last post2015-01-08 20:19 -0500
Articles 4 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  JavaFX large image crashes ImageView Jeff Higgins <jeff@invalid.invalid> - 2015-01-07 20:32 -0500
    Re: JavaFX large image crashes ImageView Knute Johnson <eternal@knutejohnson.com> - 2015-01-07 18:26 -0800
      Re: JavaFX large image crashes ImageView Jeff Higgins <jeff@invalid.invalid> - 2015-01-07 21:28 -0500
    Re: JavaFX large image crashes ImageView Jeff Higgins <jeff@invalid.invalid> - 2015-01-08 20:19 -0500

#30656 — JavaFX large image crashes ImageView

FromJeff Higgins <jeff@invalid.invalid>
Date2015-01-07 20:32 -0500
SubjectJavaFX large image crashes ImageView
Message-ID<m8kmq0$77h$1@dont-email.me>
New to JavaFX.
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:

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);
   }
}

I get stack trace:

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)

But this works:
I just can't see the image because no scroll, etc.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class LoadImage extends Application {

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

   @Override
   public void start(Stage primaryStage) {
     primaryStage.setTitle("Load Image");

     StackPane sp = new StackPane();
     Image img = new Image("file:///home/jeff/001.jpg");
     ImageView imgView = new ImageView(img);
     sp.getChildren().add(imgView);

     Scene scene = new Scene(sp);
     primaryStage.setScene(scene);
     primaryStage.show();
   }
}

[toc] | [next] | [standalone]


#30657

FromKnute Johnson <eternal@knutejohnson.com>
Date2015-01-07 18:26 -0800
Message-ID<m8kpqr$580$1@dont-email.me>
In reply to#30656
On 1/7/2015 17:32, Jeff Higgins wrote:
> New to JavaFX.
> 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:
>
> 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);
>    }
> }
>
> I get stack trace:
>
> 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)
>
> But this works:
> I just can't see the image because no scroll, etc.
>
> import javafx.application.Application;
> import javafx.scene.Scene;
> import javafx.scene.image.Image;
> import javafx.scene.image.ImageView;
> import javafx.scene.layout.StackPane;
> import javafx.stage.Stage;
>
> public class LoadImage extends Application {
>
>    public static void main(String[] args) {
>      Application.launch(args);
>    }
>
>    @Override
>    public void start(Stage primaryStage) {
>      primaryStage.setTitle("Load Image");
>
>      StackPane sp = new StackPane();
>      Image img = new Image("file:///home/jeff/001.jpg");
>      ImageView imgView = new ImageView(img);
>      sp.getChildren().add(imgView);
>
>      Scene scene = new Scene(sp);
>      primaryStage.setScene(scene);
>      primaryStage.show();
>    }
> }
>

I didn't use your image, I used a large JPEG I had (4128x2322).  The 
program compiled but when I ran it, it took several seconds to open the 
window and had no image and no scrollpane.  No errors either.  I'm 
barely JavaFX literate but I don't know what your problem is.

[toc] | [prev] | [next] | [standalone]


#30658

FromJeff Higgins <jeff@invalid.invalid>
Date2015-01-07 21:28 -0500
Message-ID<m8kq2j$5r6$1@dont-email.me>
In reply to#30657
On 01/07/2015 09:26 PM, Knute Johnson wrote:

> I didn't use your image, I used a large JPEG I had (4128x2322).  The
> program compiled but when I ran it, it took several seconds to open the
> window and had no image and no scrollpane.  No errors either.  I'm
> barely JavaFX literate but I don't know what your problem is.
>
I got the scrollbars - along with the stacktrace and no image.
Thanks for the confirmation.

[toc] | [prev] | [next] | [standalone]


#30668

FromJeff Higgins <jeff@invalid.invalid>
Date2015-01-08 20:19 -0500
Message-ID<m8nadn$322$1@dont-email.me>
In reply to#30656
On 01/07/2015 08:32 PM, Jeff Higgins wrote:
> New to JavaFX.
> Is my example code flawed?
Shrugs.
> Is there a problem with large images in JavaFX?
Perhaps, see below.
> Something else?
Perhaps, see below.

In an answer at stackoverflow a certain José Pereda
helpfully pointed me to some resources.
<http://stackoverflow.com/questions/27840362/javafx-large-image-crash>

Perhaps there are problems with large images in JavaFX.
Perhaps my hardware is not up to the task.
Using the -Dprism.verbose=true switch, I see that I'm not able to use
hardware acceleration.

Do I really need all that?
I'm able to wrangle that image and more in Swing and SWT!

Prism pipeline name = com.sun.prism.es2.ES2Pipeline
Loading ES2 native library ... prism_es2
	succeeded.
GLFactory using com.sun.prism.es2.X11GLFactory
(X) Got class = class com.sun.prism.es2.ES2Pipeline
Failed Graphics Hardware Qualifier check.
System GPU doesn't meet the es2 pipe requirement
Prism pipeline name = com.sun.prism.sw.SWPipeline

GraphicsPipeline.createPipeline: error initializing pipeline 
com.sun.prism.es2.ES2Pipeline
*** Fallback to Prism SW pipeline

It's all too bad. I have a nice little Swing image annotation
application that I think would benefit from the JavaFX
scenegraph rather that my little homemade one but now it seems
I'll be unable to try it.

Boo hoo.


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web