Jump to content

cant upload background images


vladbuff

Recommended Posts

I'm currently following Explv's tutorials on scripting and was following his paint tutorial and I was having issues when it came to uploading a background image. When i had the code in a normal script no background image would be uploaded but I wouldn't get any errors so to try and trouble shoot i created a script containing only the paint code to try and upload the background image but it wont even register as a script when i export it to the osbot script folder. I would really appreciate if someone can point out what I may be doing wrong. Using Eclipse IDE here's what i wrote: 

package core;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.osbot.rs07.script.Script;

public class BackgroundTest extends Script {

BufferedImage background;

@Override
public void onStart() {

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


@Override
public final int onLoop() throws InterruptedException {
// TODO Auto-generated method stub
return 0;
}


public void onPaint(Graphics2D g) {
if(background != null) {
g.drawImage(background, null, 300, 300);
}
}
}

 


 

Edited by vladbuff
Link to comment
Share on other sites

3 minutes ago, vladbuff said:

okay that's huge i can actually launch the script now but it still doesn't draw an imagine onto the screen is there something else I need to do to actually get a background image to show up?

drawImage(Image img,
                   int x, int y,
                   ImageObserver observer);

It looks like you're inputting a null x coord, try doing 

 

g.drawImage(background, 300, 300, null);
  • Heart 1
Link to comment
Share on other sites

https://gyazo.com/6fa217daea890867e9591e369da18e31

 

this is a screenshot of where the resources folder is located and the image inside of it if that's relevant, i also looked at another thread with a seemingly similar problem where the solution was to verify that the image is getting exported correctly which it is

4 minutes ago, Muffins said:
drawImage(Image img,
                   int x, int y,
                   ImageObserver observer);

It looks like you're inputting a null x coord, try doing 

 

g.drawImage(background, 300, 300, null);

will try that now!

 

Link to comment
Share on other sites

2 minutes ago, vladbuff said:

https://gyazo.com/6fa217daea890867e9591e369da18e31

 

this is a screenshot of where the resources folder is located and the image inside of it if that's relevant, i also looked at another thread with a seemingly similar problem where the solution was to verify that the image is getting exported correctly which it is

will try that now!

 

the img might need to be in the /osbot/data/ folder as well.

Link to comment
Share on other sites

Just now, Muffins said:

the img might need to be in the /osbot/data/ folder as well.

changing the x coords didnt seem to affect the outcome there isnt an image printing and i do have the same background.png saved in osbot/data/ unfortunately i might just try changing the image im trying to use as as a background image and see if that helps

Link to comment
Share on other sites

14 hours ago, vladbuff said:

changing the x coords didnt seem to affect the outcome there isnt an image printing and i do have the same background.png saved in osbot/data/ unfortunately i might just try changing the image im trying to use as as a background image and see if that helps

Try something like this in you onStart to load an image and draw that image in your onPaint :)

public static File imageFile = new File(System.getProperty("user.home") + File.separator + "OSBot" + File.separator + "Data" + File.separator + "image.png");

try {
    BufferedImage image = ImageIO.read(imageFile);
} catch (IOException e) {
    e.printStackTrace();
}
 
Edited by Khaleesi
  • Like 1
Link to comment
Share on other sites

10 hours ago, Khaleesi said:

Try something like this in you onStart to load an image and draw that image in your onPaint :)

public static File imageFile = new File(System.getProperty("user.home") + File.separator + "OSBot" + File.separator + "Data" + File.separator + "image.png");

try {
    BufferedImage image = ImageIO.read(imageFile);
} catch (IOException e) {
    e.printStackTrace();
}
 

alright so i commented out the old BufferedImage code and implemented this into my onstart method but it doesnt let me use the value of image in my onPaint method am i putting everything into the right spot of my code or do i need to change the typing on my onStart or onPaint from void to something else?

package core;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "BackgroundTest", author = "VladBuff", info = "", version = 0.1, logo = "")

public class BackgroundTest extends Script {
	
	//BufferedImage background;
	
	public static File imageFile = new File(System.getProperty("user.home") + File.separator + "OSBot" + File.separator + "Data" + File.separator + "background.png");

	@Override
	public void onStart() {
			
		try {
		    BufferedImage image = ImageIO.read(imageFile);
		} catch (IOException e) {
		    e.printStackTrace();
		}
	
		
		/*
		try {
			
			background = ImageIO.read(BackgroundTest.class.getResourceAsStream("/resources/background.png"));			
		} catch(IOException e) {
			log(e);
		}
		*/
		}
		 
	
	@Override
	public final int onLoop() throws InterruptedException {
		// TODO Auto-generated method stub
		return 0;
	}
		
		public void onPaint(Graphics2D g) {
			
			
		if(image != null) {
			g.drawImage(image, null, 0, 0);
			
		}
	}
				
}

 

Link to comment
Share on other sites

On 1/6/2024 at 8:55 PM, vladbuff said:

alright so i commented out the old BufferedImage code and implemented this into my onstart method but it doesnt let me use the value of image in my onPaint method am i putting everything into the right spot of my code or do i need to change the typing on my onStart or onPaint from void to something else?

package core;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "BackgroundTest", author = "VladBuff", info = "", version = 0.1, logo = "")

public class BackgroundTest extends Script {
	
	//BufferedImage background;
	
	public static File imageFile = new File(System.getProperty("user.home") + File.separator + "OSBot" + File.separator + "Data" + File.separator + "background.png");

	@Override
	public void onStart() {
			
		try {
		    BufferedImage image = ImageIO.read(imageFile);
		} catch (IOException e) {
		    e.printStackTrace();
		}
	
		
		/*
		try {
			
			background = ImageIO.read(BackgroundTest.class.getResourceAsStream("/resources/background.png"));			
		} catch(IOException e) {
			log(e);
		}
		*/
		}
		 
	
	@Override
	public final int onLoop() throws InterruptedException {
		// TODO Auto-generated method stub
		return 0;
	}
		
		public void onPaint(Graphics2D g) {
			
			
		if(image != null) {
			g.drawImage(image, null, 0, 0);
			
		}
	}
				
}

 

You obviously have to put that variable outside the onStart to use it in the onPaint 
Just like u did with the background variable :)

  • Heart 1
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...