Results 1 to 9 of 9
Thread: Java image load
- 09-08-2012, 10:32 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 28
- Rep Power
- 0
Java image load
I am trying to learn how load an image file in java. I've done this in an applet but cannot load it in a application.
Here is the code
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
public class Main extends JFrame {
public static void main(String[] args)
{
ImageLoad();
}
public static void ImageLoad()
{
BufferedImage img = null;
try {
img = ImageIO.read(new File("C:/slime.jpg"));
}
catch (IOException e)
{ ;
}
System.out.print(img);
}// Image load method end
}//End of Main class
I am returning the data as console, but how do i return the actual image?
Thanks for the help
- 09-08-2012, 10:37 PM #2
Re: Java image load
If the image's bytes are in an object, return a reference to that object.how do i return the actual image
I'm not sure what you mean by "return" for an image. Can you explain?
BTW You shouldn't leave catch blocks empty and ignore any exceptions. Add a call to printStackTrace() to the catch block.If you don't understand my response, don't ignore it, ask a question.
- 09-09-2012, 12:05 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 28
- Rep Power
- 0
- 09-09-2012, 01:38 AM #4
Re: Java image load
One way is make the image an Icon and add it to a JLabel
or create a JPanel, override its paintComponent() method and draw the image.If you don't understand my response, don't ignore it, ask a question.
- 09-09-2012, 03:03 AM #5
Re: Java image load
Why do they call it rush hour when nothing moves? - Robin Williams
- 09-10-2012, 09:58 PM #6
Member
- Join Date
- Sep 2012
- Posts
- 28
- Rep Power
- 0
Re: Java image load
Can you paste some code or be more specific pls
- 09-10-2012, 10:02 PM #7
Re: Java image load
This is a forum, not a code factory.
How to Use Icons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-10-2012, 10:06 PM #8
Re: Java image load
There are lots of code samples on the forum. Try doing a Search here for code: ImageIcon and drawImage
If you don't understand my response, don't ignore it, ask a question.
- 09-11-2012, 12:11 AM #9
Member
- Join Date
- Sep 2012
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Load image from jar
By sublixt in forum Java 2DReplies: 2Last Post: 10-17-2011, 12:15 AM -
How to load an image using Toolkit
By pappyj77 in forum AWT / SwingReplies: 7Last Post: 07-25-2011, 01:16 PM -
Load percentage of an image
By trishtren in forum Java 2DReplies: 0Last Post: 04-15-2011, 02:02 PM -
Can not load image in SWT/Eclipse
By janice in forum SWT / JFaceReplies: 4Last Post: 10-03-2008, 04:53 PM -
Help with load image
By trill in forum New To JavaReplies: 1Last Post: 08-01-2007, 07:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks