Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Loading an image into your script as paint.


    KCBot

    Recommended Posts

    Saw some people on the Discord having issues with this.


    Above your onStart create a BufferedImage like this:

    private BufferedImage image;



    Paste this on your onStart():

    try {
                URL imageUrl = new URL("https://IMAGEHERE.COM/NOIMGURUSEIMGBB");
                image = ImageIO.read(imageUrl);
                if (image == null) {
                    log("Image could not be loaded.");
                }
            } catch (IOException e) {
                log("Error loading image: " + e.getMessage());
            }


    Then in your onPaint() paste this:
     

    if (image != null) {
                graphics.drawImage(image, 10, 215, null);
            }
    
    The 10 and 215 are the X and Y where the image will be loaded.



    That should be it!

    Link to comment
    Share on other sites

    I strongly dislike grabbing an image from the internet rather than just plopping it in your source directory and grabbing it as such:

    private Image getIconImage(String iconPath){
        try{
            return ImageIO.read(getClass().getResourceAsStream(iconPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

     

    Is there any reason not to do this? I've seen many snippets where the image is grabbed from a URL. Just curious as to why.

    Link to comment
    Share on other sites

    2 hours ago, morten1ela said:

    I strongly dislike grabbing an image from the internet rather than just plopping it in your source directory and grabbing it as such:

    private Image getIconImage(String iconPath){
        try{
            return ImageIO.read(getClass().getResourceAsStream(iconPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

     

    Is there any reason not to do this? I've seen many snippets where the image is grabbed from a URL. Just curious as to why.

    I did this and it got denied with
    "You can't load images like that in SDN scripts. You need to load them from the internet."

    I tried using imgur but it wouldn't work so I used imgbb which works and others use.

    Link to comment
    Share on other sites

    On 4/12/2024 at 11:03 PM, Meteorite said:

    I did this and it got denied with
    "You can't load images like that in SDN scripts. You need to load them from the internet."

    I tried using imgur but it wouldn't work so I used imgbb which works and others use.

    Oh wow I didn't know that. I don't plan on ever releasing my scripts to the SDN (partially because I suck at coding), so I guess I won't have to deal with that.

    Edited by morten1ela
    Link to comment
    Share on other sites

    • 1 month later...

    For other readers and googlers on this topic

    this is the code I used for GUI when setting an icon on a jlabel

    headerLogo.setIcon(new ImageIcon(loadImage("https://i.ibb.co/NZZtR7r/Finishing-Logo-LUXE.png")));


    this is the code i use for loading paint
     

            image = loadImage("https://i.ibb.co/MhKGfmG/paint.jpg");
            if(getSettings().shouldUseStartTile) {
                getSettings().startArea = new Area(
                        new Tile(Players.getLocal().getX() + getSettings().radius, Players.getLocal().getY() + getSettings().radius),
                        new Tile(Players.getLocal().getX() - getSettings().radius, Players.getLocal().getY() -getSettings().radius)
                );
            }

     

    This is the key: 

    loadImage("https://UR URL HERE!!.jpg");

    https://dreambot.org/javadocs/org/dreambot/api/utilities/Images.html#loadImage(java.lang.String)

    image.png

     

     

     

     

    image.png

    Link to comment
    Share on other sites

    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
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.