vladbuff Posted January 5 Share Posted January 5 (edited) 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 January 5 by vladbuff Quote Link to comment Share on other sites More sharing options...
Muffins Posted January 5 Share Posted January 5 you need an @ScriptManifest big dog Quote Link to comment Share on other sites More sharing options...
vladbuff Posted January 5 Author Share Posted January 5 1 hour ago, Muffins said: you need an @ScriptManifest big dog 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? Quote Link to comment Share on other sites More sharing options...
Muffins Posted January 5 Share Posted January 5 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); 1 Quote Link to comment Share on other sites More sharing options...
vladbuff Posted January 5 Author Share Posted January 5 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! Quote Link to comment Share on other sites More sharing options...
Muffins Posted January 5 Share Posted January 5 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. Quote Link to comment Share on other sites More sharing options...
vladbuff Posted January 5 Author Share Posted January 5 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 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted January 6 Share Posted January 6 (edited) 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 January 6 by Khaleesi 1 Quote Link to comment Share on other sites More sharing options...
vladbuff Posted January 6 Author Share Posted January 6 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); } } } Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted January 8 Share Posted January 8 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 1 Quote Link to comment Share on other sites More sharing options...
vladbuff Posted January 8 Author Share Posted January 8 8 hours ago, Khaleesi said: You obviously have to put that variable outside the onStart to use it in the onPaint Just like u did with the background variable I AM AN IDIOT THANK YOU I appreciate you letting me figure it out a bit it has been solved 1 Quote Link to comment Share on other sites More sharing options...