2015-01-08 70 views
1

JavaFX的新功能javafx大圖像崩潰

此示例適用於小圖像。 但大圖像崩潰ImageView。

我的示例代碼是否有缺陷? JavaFX中的大圖像有問題嗎? 還有別的嗎?

我抓住從網頁的例子:

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

我下載和處理PDF文件:

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

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

這給了我一個5100×6600像素的圖片。

我嘗試查看圖像: 幾秒鐘顯示具有空 滾動面板和發射到控制檯堆棧跟蹤一個窗口之後。

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

堆棧跟蹤:

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) 

回答

2

有報道吉拉(你需要註冊才能閱讀)的幾個錯誤:渲染圖像

  • RT-22669

    • RT-21998 NullPointerException異常在渲染大圖像時需要處理失敗的紋理加載的情況
    • RT-22073異常來自快照時拋出尺寸比最大紋理尺寸 大...

    啓用該選項-Dprism.verbose = true來檢查您的設置。

    另外,在此link之後,還可以選擇設置視頻內存。嘗試使用「-Dprism.poolstats = true」來監視紋理池的實際使用情況以更好地確定上限,並將該限制設置爲「-Dprism.maxvram = XX」(XX = 500m,...)

    雖然我沒有測試過。你能發佈一個鏈接到你的圖片?

  • +0

    謝謝José。我現在正在工作。我會按照你提供的鏈接和你的建議。我不知道發佈圖片的好地方。如果你看到我以前的帖子,我希望你沒有按照我提供的鏈接。我的圖像可能通過使用我在原始文章中提供的鏈接和ghostscript命令進行復制。 – user4250202

    +0

    kenai網站鏈接被破壞,大概正確的是: https://bugs.openjdk.java.net/browse/JDK-8117239 https://bugs.openjdk.java.net/browse/JDK-8089112 https://bugs.openjdk.java.net/browse/JDK-8088198 也見 https://bugs.openjdk.java.net/browse/JDK-8090822 –