Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2007, 03:07 PM
Member
 
Join Date: Nov 2007
Posts: 13
shaungoater is on a distinguished road
Loading An Image Help Please!
I am fairly new to programming and am having trouble loading an image. i have looked at many online tutorials but they are all different. If someone could please tell me the actual code needed to read a file into my program and store it as a buffered image. Thankyou very much to anyone who can help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-20-2007, 04:42 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,142
hardwired is on a distinguished road
Supported image formats: You can get these with static methods in the ImageIO class. Generally it is reading gif, jpg, png and writing jpg and png up through j2se 1.4. Add support for reading and writing bmp and wbmp in j2se 1.5 and for writing gif in j2se 1.6
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.*; public class LoadImages { private JScrollPane getContent(BufferedImage image) { JPanel panel = new JPanel(new GridLayout(1,0)); panel.add(new JLabel(new ImageIcon(image))); panel.add(new JLabel(new ImageIcon(getImage()))); return new JScrollPane(panel); } private BufferedImage getImage() { String path = "images/bclynx.jpg"; // ClassLoader looks up resource which must // be located/available in the classpath. URL url = getClass().getResource(path); BufferedImage image = null; try { image = ImageIO.read(url); } catch(IOException e) { System.out.println("Read error: " + e.getMessage()); } return image; } public static void main(String[] args) throws IOException { String path = "images/mtngoat.jpg"; BufferedImage image = ImageIO.read(new File(path)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new LoadImages().getContent(image)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-09-2008, 09:14 AM
Member
 
Join Date: Jan 2008
Posts: 7
softdev is on a distinguished road
NIce Post!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic image loading in jsp ramakrishna k m JavaServer Pages (JSP) and JSTL 4 06-11-2008 10:09 PM
Loading Image from local directory nancyhung Advanced Java 0 01-29-2008 04:46 PM
Loading Images - Imp Thulasiraman Advanced Java 0 01-28-2008 10:33 AM
Converting multiple banded image into single banded image... Image enhancement archanajathan Advanced Java 0 01-08-2008 06:29 PM
problems when loading an image in servlet oregon Java Servlet 1 08-05-2007 07:02 PM


All times are GMT +3. The time now is 05:03 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org