Jump to content

Paint. Hows does it work?


Guest Apogee

Recommended Posts

Guest Apogee

I know some of the API to display paint, but i really don't want JUST text on screen. IS there a way i can put an image i made on screen? (I know it is possible due to it being done on other scripts, i'm just unsure of how.) 

If you any of you know of a thread or section that has a guide or walkthrough of all of it, a link to that would be HIGHLY appreciated. Thanks :)

Link to comment
Share on other sites

Welp it's pretty simple acutally. All you need is an Image, which you get from a URL.

 

You need to create 2 instance variables:

Image paintImg;
URL paintUrl;

then in your onStart do the following:


try {
paintUrl = new URL("yourPaint.com");
} catch (MalformedURLException e1) {
log("Problem loading URL.");
e1.printStackTrace();
}
try {
paintImg = ImageIO.read(paintUrl);
} catch (IOException e1) {
log("Problem loading image from URL.");
e1.printStackTrace();
}

Finally, paint it in your onPaint().

g.drawImage(paintImg, x, y, width,height,this);
Edited by Deffiliate
Link to comment
Share on other sites

Guest Apogee

 

Welp it's pretty simple acutally. All you need is an Image, which you get from a URL.

 

You need to create 2 instance variables:

Image paintImg;
URL paintUrl = new URL("yourPaint.com");

then in your onStart do the following:

paintImg = ImageIO.read(url); 

Finally, paint it in your onPaint().

g.drawImage(paintImg, x, y, width,height,this);

 

what would "this" be?

Link to comment
Share on other sites

Guest Apogee

 

Welp it's pretty simple acutally. All you need is an Image, which you get from a URL.

 

You need to create 2 instance variables:

Image paintImg;
URL paintUrl;

then in your onStart do the following:


try {
paintUrl = new URL("yourPaint.com");
} catch (MalformedURLException e1) {
log("Problem loading URL.");
e1.printStackTrace();
}
try {
paintImg = ImageIO.read(paintUrl);
} catch (IOException e1) {
log("Problem loading image from URL.");
e1.printStackTrace();
}

Finally, paint it in your onPaint().

g.drawImage(paintImg, x, y, width,height,this);

 

paintIMG and paintURL are both "wrong" according to eclipse. As far as i can tell, there's nothing to import.

Link to comment
Share on other sites

Guest Apogee

 

Because you haven't done this... 

856dS.png

You need to import Image and URL...

import javax.imageio.ImageIO;
import java.net.URL;

Hmmm, I have those imports and i have created the instance variables. Does it matter where i declare them?

Link to comment
Share on other sites

Guest Apogee

 

You can declare an instance variable anywhere after this:

public class MyScript extends Script {

Mmmkay, thank you for the help. You're practically spoon feeding me and i can't get this to work. I'll figure it out. smile.png

If it helps,

http://gyazo.com/d8b1cbcb019ab0467589d88d9053922c

 

 

EDIT: Solved that issue, Now i'm getting this.

http://gyazo.com/660780ce0d959268249e89b5c1a6d35d

Edited by Bitter
Link to comment
Share on other sites

Mmmkay, thank you for the help. You're practically spoon feeding me and i can't get this to work. I'll figure it out. smile.png

If it helps,

http://gyazo.com/d8b1cbcb019ab0467589d88d9053922c

/no problem. remove the URL and Image here: http://puu.sh/85795.png, you've already got it declared about.

Link to comment
Share on other sites

Guest Apogee

uhmm simplest option would be to change "this" to null.

PERFECT. Can i rep you without actually doing a transaction with you? I went to rep and it was making me choose from buyer, or seller or something. :x

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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