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 01-23-2008, 10:53 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
BuffededImage cache
Hello everyone

I've been using BufferedImage objects for some time and I noticed something strange. When I use the ImageIO.read() method to read an image from the hard drive and I draw the image somewhere in a thread, I found that it is very slow. But, if I load the image in some BufferedImage object, say A, create a new Instance of BufferedImage B and draw A onto B using the BufferedImage.getGraphics() method, I found that rendering B is much faster. Can someone please explain this and perhaps show me a better way of using the BufferedImage for performance.

Thank you
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 01:00 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
Try an image type based on your local configuration.
On ms vista I get:
Code:
C:\jexp>java ImageTypes loaded image type = 5 compatible dst type = 1
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class ImageTypes { private JScrollPane getContent(BufferedImage image) { System.out.println("loaded image type = " + image.getType()); JPanel panel = new JPanel(new GridLayout(1,0)); panel.add(wrap(image)); panel.add(wrap(convert(image))); panel.add(wrap(convert(image, BufferedImage.TYPE_INT_RGB))); return new JScrollPane(panel); } private BufferedImage convert(BufferedImage src) { int w = src.getWidth(); int h = src.getHeight(); BufferedImage dst = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage(w, h); // Component has a getGraphicsConfiguration method. System.out.println("compatible dst type = " + dst.getType()); Graphics2D g2 = dst.createGraphics(); g2.drawImage(src,0,0,null); g2.dispose(); return dst; } private BufferedImage convert(BufferedImage src, int type) { int w = src.getWidth(); int h = src.getHeight(); BufferedImage dst = new BufferedImage(w, h, type); Graphics2D g2 = dst.createGraphics(); g2.drawImage(src,0,0,null); g2.dispose(); return dst; } private JLabel wrap(BufferedImage image) { JLabel label = new JLabel(new ImageIcon(image)); label.setHorizontalAlignment(JLabel.CENTER); return label; } public static void main(String[] args) throws IOException { String path = "images/blackBear.jpg"; BufferedImage image = ImageIO.read(new File(path)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new ImageTypes().getContent(image)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
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
clear cache Jadellll New To Java 0 03-20-2008 10:27 AM
JSP - using connection cache Java Tip Java Tips 0 01-30-2008 10:54 AM
cache problem in jsp lpwing JavaServer Pages (JSP) and JSTL 4 01-15-2008 08:43 AM
how to restict cache fred JavaServer Pages (JSP) and JSTL 1 07-24-2007 02:56 AM
Caché Monitor 0.35 levent Java Announcements 0 06-10-2007 02:40 PM


All times are GMT +3. The time now is 06:12 PM.


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