解决方法
根据这个博文:
http://i-proving.com/2006/07/06/java-advanced-imaging/你可以使用
Java Advanced Imaging Library做你想要的.以下示例代码应为您提供一个良好的起点.这将调整图像的高度和宽度,以及图像质量.一旦您的图像具有所需的文件大小,您可以在显示图像时将其缩放到所需的像素高度和宽度.
// read in the original image from an input stream SeekableStream s = SeekableStream.wrapInputStream( inputStream,true); RenderedOp image = JAI.create("stream",s); ((OpImage)image.getRendering()).setTileCache(null); // now resize the image float scale = newWidth / image.getWidth(); RenderedOp resizedImage = JAI.create("SubsampleAverage",image,scale,qualityHints); // lastly,write the newly-resized image to an // output stream,in a specific encoding JAI.create("encode",resizedImage,outputStream,"PNG",null);