Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

GetApplet location

  Asked By: Kenneth    Date: Jul 13    Category: Java    Views: 564
  

I have an Applet where we see video from a webcam. There
is also a button that, when is pressed, captures to a jpeg the frame
that is currently in the container. The problem is that i only want
to capture the picture in the JPanel where the video runs. The code
of the method is the following:

Toolkit tk = Toolkit.getDefaultToolkit();
tk.sync();
Rectangle ecran = new Rectangle(this.getLocation().x,
this.getLocation().y,
mediaPanel.getWidth(),
mediaPanel.getHeight());
Robot robot=new Robot();
robot.setAutoDelay(0);
robot.setAutoWaitForIdle(false);
BufferedImage image = robot.createScreenCapture(ecran);
File file = new File(fileName+(a++)+".jpeg");
javax.imageio.ImageIO.write(image, "JPEG", file);

"this" refers to the applet and "mediaPanel" refers to the JPanel
where the video runs. "a" is just a counter to add to the filename.

In the place where is getLocationX and Y i have already tried
this.getAlignmentX, this.getX and mediaPanel.getX. None of them
works.

Can someone PLEASE tell me how to capture the screen only where the
Jpanel of the Applet is placed?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Alfonso Martin     Answered On: Jul 13

You can disable the capture  to JPEG button  by default. and when the video
play is pressed  or when the video  starts playing then you can enable the button.
You can achieve the same by keeping a boolean variable and keeping its value
to true when the video is running or else false.
You can capture picture  from the panel without using the coordinates. Just
write a method  in the panel itself that returns the image  object. In this way
you are not worried about the panel's coordinates

 
Didn't find what you were looking for? Find more on GetApplet location Or get search suggestion and latest updates.




Tagged: