Aeon 43 Share Posted August 1, 2020 As the title says, I'm trying to add an image to the screen for my script, but I can't seem to get it to work properly. I found this thread which has a bunch of dead screenshots so it wasn't too useful. Any help in pointing me in the direction would be greatly appreciated! Link to comment Share on other sites More sharing options...
Pixel_Life 24 Share Posted August 1, 2020 See Hashtag's tutorial here: The "Drawing an image" section. Super simple, that's the tutorial that helped me with it Link to comment Share on other sites More sharing options...
Succulent 18 Share Posted August 1, 2020 Step 1: Add this method to your main class to return Image objects from a URL: private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) { e.printStackTrace(); } return null; } Step 2: Create an Image property to store the image using this method: private final Image paintBackground = getImage("https://i.imgur.com/Muw7swQ.png"); Step 3: Draw the image using graphics in onPaint: if (paintBackground != null) { g.drawImage(paintBackground, 30, 316, null); } Sources: Link to comment Share on other sites More sharing options...
Aeon 43 Author Share Posted August 1, 2020 @Succulent Thank you! I'd read through that thread at some point and I guess I didn't remember reading that... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.