// 获得原始图片的宽度及高度
int width = originalImage.getWidth();
int height = originalImage.getHeight();
// 判断是否有必要缩放
if (width > 0 || height > 0) {
AdvancedResizeOp resizeOp = new ThumpnailRescaleOp(newWidth, newHeight);
resizeOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
BufferedImage thumbnailImage = resizeOp.filter(originalImage, null);
ImageIO.write(thumbnailImage, format, thumbnailStream);
}
} finally {
if (originalStream != null) {
originalStream.close();