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?