Results 1 to 4 of 4
- 02-15-2012, 09:54 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Loading a image with Image and ImageIcon
Hey guys,
I am trying to load a picture and i really don't know what i am doing wrong. I have been reading up on Image and ImageIcon but i still can't oad the image.
Here is my code:
Java Code:package oop_po2; import java.awt.Image; import java.io.IOException; import java.io.FileNotFoundException; import javax.swing.ImageIcon; public class OOP_PO2_Test { public Image getImage(String filename) { Image image = null; ImageIcon tattoo = new ImageIcon(filename); return image; } public static void main(String args[]) throws FileNotFoundException { OOP_PO2_Test app = new OOP_PO2_Test(); Image image = app.getImage("tattoo.jpeg"); // TODO OOP_PO2_A2: Fill in the path to an existing image if (image != null && image instanceof Image) { System.out.println("Successfully loaded the image file."); } else { System.out.println("Nothing loaded. Try again."); } } }
- 02-15-2012, 10:01 AM #2
Re: Loading a image with Image and ImageIcon
Have you gone through How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) ?I have been reading up on Image and ImageIcon
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-15-2012, 10:17 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Re: Loading a image with Image and ImageIcon
Yes i have also been reading Image : Java Glossary
It seems i just don't get it..... and yes i am still a beginner with JAVA :)
- 02-15-2012, 10:38 AM #4
Re: Loading a image with Image and ImageIcon
What do you think this method returns?
Also note that it's superfluous to construct an ImageIcon only for the sake of retrieving its Image; either use the ImageIcon as an Icon or load the Image using ImageIO#read(...).Java Code:public Image getImage(String filename) { Image image = null; ImageIcon tattoo = new ImageIcon(filename); return image; }
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Java Applet loading image; render as you get image?
By ea25 in forum New To JavaReplies: 12Last Post: 04-14-2011, 01:58 PM -
Help needed setting ImageIcon image
By ben1989 in forum Java AppletsReplies: 20Last Post: 05-05-2010, 03:16 AM -
ImageIcon won't load my image
By JaiRaj in forum AWT / SwingReplies: 5Last Post: 03-04-2010, 06:35 PM -
How to insert Image using ImageIcon
By anjali.wadhwa in forum New To JavaReplies: 5Last Post: 01-15-2010, 11:08 PM -
ImageIcon : Image not displayed
By niteshwar.bhardwaj in forum Java 2DReplies: 0Last Post: 02-13-2009, 07:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks