Results 1 to 3 of 3
Thread: Understanding Images
- 07-28-2013, 08:58 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 8
- Rep Power
- 0
Understanding Images
So i've been trying to make a basic class to draw an image onscreen, and given that i could never make it work i had assumed that the issue was with the code until i coded the absolute path to the image resource and then it worked just fine. That being the case i think my issue is with how to utilize resources that have been imported into the project file. What i did was to go into the properties of the image and then copy/paste the path into the parameters of an ImageIcon. I can't understand for the life of my why this doesn't work and the absolute path does. Any thoughts?
Note my main method does nothing but call this. I'm using Eclipse so i can just drag and drop resources into the project. I've tried the path both with and without the preceding '/'. I've also tried both using and not using a sub-folder to house the files. Am i missing something? Thanks in advance.
Java Code:import javax.swing.ImageIcon; import javax.swing.JFrame; import java.awt.*; public class Screen extends JFrame { Image img; ImageIcon i = new ImageIcon("ImageTests/images/SpriteSheet.png"); public Screen(){ this.setSize(640, 480); this.setTitle("My UI"); this.setVisible(true); } public void paint(Graphics g){ g.drawRect(10, 10, 50, 50); img = i.getImage(); g.drawImage(img, 100, 100, null); } }
Last edited by TheUncertainyAnswer; 07-28-2013 at 11:55 PM.
- 07-29-2013, 02:09 AM #2
Member
- Join Date
- Jul 2013
- Posts
- 5
- Rep Power
- 0
Re: Understanding Images
Hi. Try using the awt Toolkit to retrieve images from the local file system.
Toolkit (Java Platform SE 7 )
- 07-29-2013, 08:19 AM #3
Re: Understanding Images
No, that won't help; you need to have the correct path to the resource.
Go through Loading Images Using getResource
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
Get PDF File as Images & Extract Text from Images Using REST APIs
By saaspose in forum Java SoftwareReplies: 0Last Post: 11-14-2012, 12:15 PM -
Need some understanding and help!
By Kevinius in forum New To JavaReplies: 8Last Post: 05-14-2011, 06:50 AM -
how to mark on 2 images at a time,both images are on different JPanel
By smitharavi in forum AWT / SwingReplies: 0Last Post: 12-16-2010, 06:14 PM -
how to scroll 2 images at a time(synchronisation),both images are on different panels
By smitharavi in forum AWT / SwingReplies: 4Last Post: 12-16-2010, 05:32 PM -
Help on understanding a program
By newbie225 in forum New To JavaReplies: 1Last Post: 11-10-2009, 01:53 AM
Bookmarks