java - JavaFX screencapture headless exception on OSX -
i'm converting old java app swing javafx , i'm running problem.
i'm using next code capture screenshots:
public screencapper() { ge = graphicsenvironment.getlocalgraphicsenvironment(); gs = ge.getscreendevices(); seek { robot = new robot(gs[gs.length-1]); } grab (awtexception e) { logger.getinstance().error("error creating screenshot robot instance!"); } } public color capture() { rectangle bounds; mode = gs[0].getdisplaymode(); bounds = new rectangle(0, 0, mode.getwidth(), mode.getheight()); //...... }
this works fine when running application under windows. when running under osx in next exception:
exception in application start method exception in thread "main" java.lang.runtimeexception: exception in application start method @ com.sun.javafx.application.launcherimpl.launchapplication1(launcherimpl.java:403) @ com.sun.javafx.application.launcherimpl.access$000(launcherimpl.java:47) @ com.sun.javafx.application.launcherimpl$1.run(launcherimpl.java:115) @ java.lang.thread.run(thread.java:722) caused by: java.awt.headlessexception @ sun.java2d.headlessgraphicsenvironment.getscreendevices(headlessgraphicsenvironment.java:72) @ be.beeles_place.roggbiv.utils.screencapper.<init>(screencapper.java:33) @ be.beeles_place.roggbiv.modes.averagecolormode.start(averagecolormode.java:31) @ be.beeles_place.roggbiv.modes.colormodecontext.startcurrentcolormode(colormodecontext.java:28) @ be.beeles_place.roggbiv.controller.roggbivcontroller.<init>(roggbivcontroller.java:42) @ be.beeles_place.roggbiv.roggbivmain.start(roggbivmain.java:67) @ com.sun.javafx.application.launcherimpl$5.run(launcherimpl.java:319) @ com.sun.javafx.application.platformimpl$5.run(platformimpl.java:215) @ com.sun.javafx.application.platformimpl$4$1.run(platformimpl.java:179) @ com.sun.javafx.application.platformimpl$4$1.run(platformimpl.java:176) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.application.platformimpl$4.run(platformimpl.java:176) @ com.sun.glass.ui.invokelaterdispatcher$future.run(invokelaterdispatcher.java:76)
this think has todo javafx appearently running headless mode on osx, next debug warnings suggest:
013-03-10 10:44:03.795 java[1912:5903] *** warning: method userspacescalefactor in class nsview deprecated on 10.7 , later. should not used in new applications. utilize convertrecttobacking: instead. 2013-03-10 10:44:05.472 java[1912:707] [jrsappkitawt markappisdaemon]: process manager initialized: can't enable headless mode.
is there way work? or way capture screenshots not conflict osx?
full code @ https://github.com/beele/roggbiv
javafx doesn't utilize awt stack, it's not beingness started in pure javafx application. due threads handling specifics awt beingness run in headless mode on mac requested javafx.
there next options solve that:
use voodoo magic initialize awt -- in static initialization run java.awt.toolkit.getdefaulttoolkit();
edit worked in older javafx, sorry
better options opt out of using awt javafx. can utilize next functionality create screenshots: http://docs.oracle.com/javafx/2/api/javafx/scene/node.html#snapshot%28javafx.util.callback,%20javafx.scene.snapshotparameters,%20javafx.scene.image.writableimage%29
edit alexander pointed out way run awt code in separate vm. accomplish can refactor screenshot functionality separate class , phone call javafx app by:
new processbuilder( system.getproperty("java.home") + "/bin/java", "-cp", "classpath", "my.apps.doscreenshot" ).start();
this app can store screenshot filesystem. if need screenshots , met performance issues can run separate app 1 time , communicate through socket.
use com.sun.glass.ui.robot
instead of awtrobot
java osx awt javafx-2
No comments:
Post a Comment