/**
* 图像缩放 - 参数指定目标图缩放比例。
* @param srcImage 源图像对象。
* @param xscale 图像 x 轴(宽度)上的的缩放比例。
* @param yscale 图像 y 轴(高度)上的的缩放比例。
* @param hints 重新绘图使用的 RenderingHints 对象。
* @return 缩放后的图像对象。
*/
 public static BufferedImage scaleJ2D(BufferedImage srcImage, double xscale, double yscale, RenderingHints hints) ...{
AffineTransform affineTransform = new AffineTransform();
affineTransform.scale(xscale, yscale);
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, hints);
int width = (int)((double)srcImage.getWidth() * xscale);
int height = (int)((double)srcImage.getHeight() * yscale);
BufferedImage dstImage = new BufferedImage(width, height, srcImage.getType());
return affineTransformOp.filter(srcImage, dstImage);
}
 /** *//**
* 图像缩放 - 参数指定缩放后的目标图宽高。
* @param srcImage 源图像对象。
* @param dstWidth 目标图的宽度。
* @param dstHeight 目标图的高度。
* @param hints 重新绘图使用的 RenderingHints 对象。
* @return 缩放后的图像对象。
*/
 public static BufferedImage scaleJ2D(BufferedImage srcImage, int dstWidth, int dstHeight, RenderingHints hints) ...{
float xscale = (float) dstWidth / (float) srcImage.getWidth();
float yscale = (float) dstHeight / (float) srcImage.getHeight();
return scaleJ2D(srcImage, xscale, yscale, hints);
}
|