need robust tobufferedImage() method

this method converts Image to BufferedImage.

private BufferedImage toBufferedImage(Image image,int type){

int w = image.getWidth(null);

int h = image.getHeight(null);

BufferedImage result =new BufferedImage(w, h, type);

Graphics2D g = result.createGraphics();

g.drawImage(image, 0, 0,null);

g.dispose();

return result;

}

it works good for image files that aren't compressed.

however when i try it with a compressed 8MB tiff file it throws the following exception:

java.lang.OutOfMemoryError: Java heap space

at java.awt.image.DataBufferInt.<init>(Unknown Source)

at java.awt.image.Raster.createPackedRaster(Unknown Source)

at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)

at java.awt.image.BufferedImage.<init>(Unknown Source)

at upload.ImageProcessor.toBufferedImage(ImageProcessor.java:243)

at upload.ImageProcessor.Crop(ImageProcessor.java:188)

what could be the problem ?

how can i write a robust tobufferedImage() method that supports tiff compressed files?

thanks.

[1502 byte] By [Servant@AKa] at [2007-11-27 4:00:08]
# 1

Uhhhhh ... Just a guess here but I think you might be running out of memory.

Ok all kidding aside, you may be able to push up the memory allocated to the JVM (there are settings on the JVM to control this though the details in part depend on your OS) and solve your problem that way.

PS.

puckstopper31a at 2007-7-12 9:04:44 > top of Java-index,Java Essentials,Java Programming...
# 2
I don't think it's the compression, just the dimensions. What is the width and height of that image?
DrLaszloJamfa at 2007-7-12 9:04:44 > top of Java-index,Java Essentials,Java Programming...
# 3
ok thanks guys i solved the problem .the third party image library i'm using has already a getAsBufferedImage() method & that one seems to have solved the issue.thanks again
Servant@AKa at 2007-7-12 9:04:44 > top of Java-index,Java Essentials,Java Programming...