[Java] Eclipse RCP Plugin: problems with Screen.userCapture()

Asked by flip

Hi,

i'm trying use CapturePrompt in a java eclipse application but hang after select region.
My code:

Screen screen = new Screen();
CapturePrompt cp = new CapturePrompt(screen);
cp.prompt();

Region gray don't dissapear and i obtain this exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
 at org.sikuli.script.CapturePrompt.notifyObserver(CapturePrompt.java:44)
 at org.sikuli.script.CapturePrompt$1.mouseReleased(CapturePrompt.java:197)
 at java.awt.Component.processMouseEvent(Unknown Source)
 at java.awt.Component.processEvent(Unknown Source)
 at java.awt.Container.processEvent(Unknown Source)
 at java.awt.Window.processEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)

Any help? What's wrong?
Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

CapturePrompt is only half of the story: only the overlay window, without the capture logic behind. It is not really a public API.
(from: http://sikuli.org/doc/java-x/)

to operate a capture:

ScreenImage scrImg = screen.capture(); // whole screen
String scrImgFile = scrImg.getFilename(); // stores image file as png in temp

or more compact:
String scrImgFile = screen.capture().getFilename();

If you want to store your image in a specific location:

ScreenImage scrImg = screen.capture(); // whole screen
BufferedImage scrImgFile = scrImg.getImage();

now you can use awt.ImageIO to write an image file wherever you want.

might help: https://answers.launchpad.net/sikuli/+question/179984

Revision history for this message
flip (flipudez) said :
#2

Thanks.
Yes, i can capture with:

Screen screen = new Screen();
ScreenImage scrImg = screen.userCapture(); // or Region reg = screen.selectRegion();

but, i'm developing a RCP plugin for eclipse when call this functionality is very very slow and i don't know why (in a standalone java application (with typical main) works fine and quick). However in the rcp, gets gray screen capture and takes about 2 minutes to leave the crosshairs to select the region (eclipse don't response).... while with capturePrompt was inmediate.

I'll try to see why the action is so slow in the rcp plugin...

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#3

ok, understood.

Come back if you have more information. Thanks

Revision history for this message
flip (flipudez) said :
#4

Hi!

I've more information about the problem.

The problem is this line in my RCP plugin:

Frame frame = SWT_AWT.new_Frame(swtAwtComponent);

This instruction hag the user capture. I'dont know why.... even if i close the view user capture hang continues....

Any help?

thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#5

You might check, wether there is some Java internal problem together with Sikuli's usage of the Java.awt.Robot class (used for the final screen capture) or wether it is a problem with Sikuli's solution (transparent overlay window) for the drawing of the region to capture.

Since you seem to setup some new Frame, you should think about rebuilding the capture feature on your own within your plugin.

Can you help with this problem?

Provide an answer of your own, or ask flip for more information if necessary.

To post a message you must log in.