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();
}

