Jump to content

Screenshot Renaming


Recommended Posts

Posted (edited)
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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