Jump to content

Picture help


Recommended Posts

Posted (edited)
15 minutes ago, scriptersteve said:

Hi, so i know how to add the picture t the script logo.

But how does one make the picture appear on screen over chatbox, Can't seem to work that out :?

 

Thanks

By overriding the onPaint method and drawing the image?

There's a bunch of threads that show you how to do this, you should try searching the forum instead of making a new thread for every trivial thing:

 

Edited by Explv
Posted (edited)
6 minutes ago, scriptersteve said:

Fair enough, i had read that 

Well it's on there, near the bottom.

( You can also use an image stored online, instead of storing in the resources directory)

Assuming your images are stored in a directory called "resources"

 

Firstly you need to read the image from the file. This should NOT be done inside the onPaint method as this would be VERY inefficient.

Declare the images you need as global variables of type BufferedImage, for example:

...
public class Main extends Script{

    BufferedImage background;
    
    @Override
    public void onStart(){

    }

    ...
}

Now we need to read the image from its file into the variable. This should be done inside onStart, as we only need to do it once:

...
public class Main extends Script{

    BufferedImage background;
    
    @Override
    public void onStart(){
        
        try{

            background = ImageIO.read(Main.class.getResourceAsStream("/resources/background.png"));
        } catch(IOException e){

            log(e);
        }
    }

    ...
}

Now that the image has been read from its file we can draw it inside the onPaint method using g.drawImage:

public class Main extends Script{

    BufferedImage background;
    
    @Override
    public void onStart(){
        
        try{

            background = ImageIO.read(Main.class.getResourceAsStream("/resources/background.png"));
        } catch(IOException e){

            log(e);
        }
    }

    ...

    @Override
    public void onPaint(Graphics2D g){

        if(background != null){

            g.drawImage(background, null, x, y);
        }

    }
}
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...