Okay. This is how I think it could be done. But it is a hack!
First make the 'offscreenImage' member public in the BattleView.
Then change your battlePrintActionPerformed() into this one:
public void battlePrintActionPerformed() {
BattleView battleView =
manager.getWindowManager().getRobocodeFrame().getBattleView();
Rectangle size = battleView.getBounds();
BufferedImage capture = new BufferedImage((int)size.getWidth(),
(int)size.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = capture.createGraphics();
g.drawImage(battleView.offscreenImage, 0, 0, null);
try {
ImageIO.write(capture, "png", new File("test.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
I think this should work, and that you'll be able to figure out the rest.
I am considering to add this as a feature request, now when it's
almost done anyways. But I will implement it the right way. ;-)
--- In
Robocode@..., "asherbaig" <devilvsevil@...> wrote:
>
> Hi Developer,
>
> I am not able to undertsand what you try to explain me.Thanks for your
> suggestion.
>
> I will gracefully thankful to you please send me the modified code of
> what you explain to me.
>
> Once again by heart thanful to you.
>
>
>
>
>
> --- In
Robocode@..., "flemmingnlarsen"
> <flemming.n.larsen@> wrote:
> >
> > You could use:
> >
> >
>
manager.getWindowManager().getRobocodeFrame().getBattleView().paint(Graphics)
> >
> > That is, you e.g. create a BufferedImage with the size of the
> > BattleView.getBounds(), and call getGraphics() on your BufferedImage,
> > which you supply as input parameter to the paint(Graphics) above.
> >
> > Now you have your screen-shot. ;-)
> >
> > Best regards,
> > - Flemming
> >
> > --- In
Robocode@..., "asherbaig" <devilvsevil@> wrote:
> > >
> > > Hi,
> > > I have done it by working very hard working on MenuBar.java under
> > > robocode.dialog.
> > >
> > > And i am able to take snapshot using key crtl-p also.
> > >
> > > Now the problem is it takes picture of active window of Robocode
game
> > > but now
> > > i want to take picture of only battleview.Is it possible.Because i
> > > just close to it.Here is the code
> > >
> > > public void battlePrintActionPerformed() {
> > > IBattleManager battleManager = manager.getBattleManager();
> > >
> > > try {
> > > battleManager.pauseBattle();
> > > String path = battleManager.getBattleFilename();
> > > Rectangle screenRect = new Rectangle(robocodeFrame.getBounds());
> > > //get the position of frame
> > > BufferedImage capture = new
> Robot().createScreenCapture(screenRect);
> > > if (path == null) {
> > > path =
saveScreenshotBattleDialog(battleManager.getBattlePath());
> > >
> > > }
> > > if (path != null) {
> > >
> > > ImageIO.write(capture, "png", new File(path));
> > > }
> > >
> > > }
> > > catch(Exception ex)
> > > {
> > > }
> > > finally {
> > > battleManager.resumeBattle();
> > > }
> > > }
> > >
> > > public void battleSaveAsActionPerformed() {
> > > IBattleManager battleManager = manager.getBattleManager();
> > >
> > > try {
> > > battleManager.pauseBattle();
> > > String path = saveBattleDialog(battleManager.getBattlePath());
> > >
> > > if (path != null) {
> > > battleManager.setBattleFilename(path);
> > > battleManager.saveBattleProperties();
> > > }
> > > } finally {
> > > battleManager.resumeBattle();
> > > }
> > > }
> > >
> > >
> > >
> > >
> > > --- In
Robocode@..., "flemmingnlarsen"
> > > <flemming.n.larsen@> wrote:
> > > >
> > > > This question cannot be answered or handled quickly.
> > > >
> > > > You could add it as a feature request for Robocode. Then we
> (Robocode
> > > > developers) will spend some time on it and perhaps include this
> > > > feature in a comming version of Robocode. :-)
> > > >
> > > > You can add feature requests for Robocode here:
> > > >
> > > >
https://sourceforge.net/tracker2/?group_id=37202&atid=419489> > > >
> > > > It will be faster for us to implement this feature than to
> explain how
> > > > to do it, as it requires a great deal of inside knowledge of how
> > > > Robocode is built up etc. And in order to explain how to do it, we
> > > > must know exactly what do to it, i.e. actually try to implement
> it for
> > > > real, and then write the documentation about how to do it. All
this
> > > > takes a great amount of effort. Hence, it's faster for us just to
> > > > implement the feature.
> > > >
> > > > However, we have to prioritize our limited time between all the
> > > > incoming feature requests etc. beside the changes we want to put
> into
> > > > the game ourselves, e.g. restructuring/refactorings to ease
> > > > maintenance and make it possible to implement more features in the
> > > future.
> > > >
> > > > Best regards,
> > > > - Flemming N. Larsen
> > > >
> > > >
> > > > --- In
Robocode@..., "asherbaig" <devilvsevil@> wrote:
> > > > >
> > > > > Hi, Developers.
> > > > >
> > > > > Please i need your help in urgent.I want to take the screenshot
> > during
> > > > > the battle using the key "CRTL P".
> > > > > I need suggestion from you ppl.How to do it and where can i put
> > it.And
> > > > > what are code i need to implement it.
> > > > >
> > > > > Please help !
> > > > >
> > > >
> > >
> >
>