please help,,, i'm facing a problem with JPEG

i'm trying to resize JPEG image, about (8-12 MB) to a small size image (about 400 KB..) but every time... apears to me... an error message (Java Memory heap)....

or, if i small the output size, the result should be an image not seems like the original...

for more information i'm using this code...

/*--

resizes a source image according to the scale multiplier argument, writes the resized image outs to a JPEG file

using the specified quality factor (maximum value equals 1.0f)

JFK derived this method by modifying the code in the following URI:

http://www.exampledepot.com/egs/javax.imageio/JpegWrite.html

the above code uses a workaround because of the bug in the Java 1.40 version of the JPEG writer

but Joe took the workaround out since the JPEG quality bug is fixed in 1.5 (actually in 1.4.1)

--*/

publicstaticvoid writeResizedJPEG (BufferedImage sourceImage, File outFile,double scale,float quality)throws IOException{

int newHeight = (int) (sourceImage.getHeight() * scale);

int newWidth = (int) (sourceImage.getWidth() * scale);

BufferedImage scaledImage =new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);

Graphics2D g = scaledImage.createGraphics();

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

g.scale(scale, scale);

g.drawRenderedImage(sourceImage,null);

// Find a jpeg writer

ImageWriter writer =null;

Iterator iter = ImageIO.getImageWritersByFormatName("jpg");

if (iter.hasNext()){

writer = (ImageWriter)iter.next();

}

// Prepare output file

ImageOutputStream ios = ImageIO.createImageOutputStream(outFile);

writer.setOutput(ios);

// Set the compression quality

ImageWriteParam iwparam =newJPEGImageWriteParam(Locale.getDefault());

iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;

iwparam.setCompressionQuality(quality);

// Write the image

writer.write(null,new IIOImage(scaledImage, null,null), iwparam);

// Cleanup

ios.flush();

writer.dispose();

ios.close();

g.dispose();

}

[3111 byte] By [amanjpro@yahoo.coma] at [2007-11-27 8:36:28]
# 1
I need your help....plz dont forget me... help me
amanjpro@yahoo.coma at 2007-7-12 20:33:25 > top of Java-index,Security,Cryptography...
# 2
please, i need your help...help me...
amanjpro@yahoo.coma at 2007-7-12 20:33:25 > top of Java-index,Security,Cryptography...
# 3
change the rendering hint from:RenderingHints.VALUE_INTERPOLATION_BICUBICto:RenderingHints.VALUE_RENDER_QUALITYand see if the result is any better.V.V.
viravana at 2007-7-12 20:33:25 > top of Java-index,Security,Cryptography...
# 4
better is to add a parameter to VM like -Xmx256m which means max heap 256MB (default is 64MB). Usually helps.
plika at 2007-7-12 20:33:25 > top of Java-index,Security,Cryptography...