Jump to content

Picture help


scriptersteve

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

10 minutes ago, scriptersteve said:

Yeah i know, my problem was i'm not quite sure where the picture needs to be saved i.e your resources/background - i was putting in my location and it isn't working

That was my problem - probs should have specified before 

"/src/emma.jpg"

is what i was using

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.
Note: Your post will require moderator approval before it will be visible.

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.

  • Recently Browsing   0 members

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