Jump to content

Screenshot Renaming


someguy567
 Share

Recommended Posts

14 hours ago, someguy567 said:

Is there a way to set the name of the screenshots taken by the Utilities method? Would be nice if I could put custom names for the screenshots


Just use your own method to take a "screenshot".

The first function will save a screenshot as C:\Users\Username\OSBot\Data\YourScriptName\Screenshots\RSAccountName\yyyy.MM.dd_HH.mm.ss.png


The second function will save a screenshot as C:\Users\Username\OSBot\Data\YourScriptName\Screenshots\RSAccountName\SpecifiedImageName.png

 

import org.osbot.rs07.Bot;
import org.osbot.rs07.canvas.paint.Painter;
import org.osbot.rs07.script.Script;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ScreenshotUtil {

    private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy.MM.dd_HH.mm.ss");

    public static void takeScreenshot(final Bot bot) throws IOException {
        takeScreenshot(bot, dateFormat.format(LocalDateTime.now()) + ".png");
    }

    public static void takeScreenshot(final Bot bot, final String imageName) throws IOException {
        Script currentScript = bot.getScriptExecutor().getCurrent();
        String scriptName = currentScript.getName();

        File screenshotDir = Paths.get(currentScript.getDirectoryData(), scriptName, "Screenshots", bot.getMethods().myPlayer().getName()).toFile();

        if (!screenshotDir.exists()) {
            screenshotDir.mkdirs();
        }

        BufferedImage gameBuffer = bot.getCanvas().getGameBuffer();

        if (gameBuffer == null) {
            return;
        }

        BufferedImage outImage = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                                    .getDefaultScreenDevice()
                                                    .getDefaultConfiguration()
                                                    .createCompatibleImage(gameBuffer.getWidth(), gameBuffer.getHeight(), 1);

        Graphics2D graphics = outImage.createGraphics();

        graphics.drawImage(gameBuffer, 0, 0, null);

        for (final Painter painter : bot.getPainters()) {
            painter.onPaint(graphics);
        }

        graphics.dispose();

        File outputFile = Paths.get(screenshotDir.getAbsolutePath(), imageName).toFile();
        ImageIO.write(outImage, "PNG", outputFile);
    }
}


 

Edited by Explv
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...