harbibot Posted January 13, 2017 Share Posted January 13, 2017 So I am trying to get a web image to display on screen to cover chatbox and use a background image I have uploaded to imgur. However, when I have the code in the script it gives me an error. I am using this method: private final Image background = getImage("url here"); And this in the onPaint: g.drawImage(background, 1, 1, null); But it says the getImage is not recognized. I tried a java exaple to call the method explicitly "Toolkit.getDefaultToolkit().getImage" with no luck. Does anyone have a 'best practice' to pulling a web image as a background for an onpaint? Quote Link to comment Share on other sites More sharing options...
Explv Posted January 13, 2017 Share Posted January 13, 2017 So I am trying to get a web image to display on screen to cover chatbox and use a background image I have uploaded to imgur. However, when I have the code in the script it gives me an error. I am using this method: private final Image background = getImage("url here"); And this in the onPaint: g.drawImage(background, 1, 1, null); But it says the getImage is not recognized. I tried a java exaple to call the method explicitly "Toolkit.getDefaultToolkit().getImage" with no luck. Does anyone have a 'best practice' to pulling a web image as a background for an onpaint? Did you even define the method getImage? Quote Link to comment Share on other sites More sharing options...
harbibot Posted January 13, 2017 Author Share Posted January 13, 2017 I was just calling on the java.awt.Toolkit getImage method. I tried converting the string to a URL for the parameters for that as well. https://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html#getImage(java.lang.String) Quote Link to comment Share on other sites More sharing options...
Explv Posted January 13, 2017 Share Posted January 13, 2017 I was just calling on the java.awt.Toolkit getImage method. I tried converting the string to a URL for the parameters for that as well. https://docs.oracle.com/javase/7/docs/api/java/awt/Toolkit.html#getImage(java.lang.String) Try Image image = ImageIO.read(URL); 1 Quote Link to comment Share on other sites More sharing options...
harbibot Posted January 13, 2017 Author Share Posted January 13, 2017 Perfect, that worked exactly like I wanted! private String sourceImage = "URL HERE"; private Image background = null; try { URL url = new URL(sourceImage); background = ImageIO.read(url); } catch (IOException e) { e.printStackTrace(); } Quote Link to comment Share on other sites More sharing options...