|
-
Dec 4th, 2002, 10:22 AM
#1
Image, BufferedImage
I use Toolkit.createImage to load images from my harddisk. This returns a java.awt.Image (the runtime class is sun.something.windows.WImage). But I need a java.awt.image.BufferedImage.
My current converter takes the dimensions of the Image and creates a new BufferedImage with those dimensions. Then I retrieve a Graphics2D from the BufferedImage and draw the Image inside. Finally I return the BufferedImage.
This works, but it is very slow. The total startup time for my app ranges from 30 seconds to 2 minutes! And most of it is the time I require to load the images.
Does anyone know a better way to convert Image to BufferedImage?
Current code:
Code:
private static class ImgListener implements java.awt.image.ImageObserver
{
public boolean imageUpdate(java.awt.Image img, int f, int x, int y, int w, int h) {
return ((f & java.awt.image.ImageObserver.ALLBITS) == 0);
}
}
private static BufferedImage createBufferedImage(java.awt.Image img)
{
// this is damn slow!
ImgListener listener = new ImgListener();
int width;
while((width=img.getWidth(listener)) < 0)
;
int height;
while((height=img.getHeight(listener)) < 0)
;
BufferedImage out = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics2D g = out.createGraphics();
while(!g.drawImage(img, new java.awt.geom.AffineTransform(), listener))
;
return out;
}
Thanks in advance!
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|