在用的图片切割方法切割一次要60-90MS,想要找个更快的方法!
public BufferedImage getSubimage(int x,
int y,
int w,
int h)
返回由指定矩形区域定义的子图像。返回的 BufferedImage 与源图像共享相同的数据数组。
参数:
x, y - 指定矩形区域的左上角坐标
w - 指定矩形区域的宽度
h - 指定矩形区域的高度
返回:
BufferedImage,它是此 BufferedImage 的子图像。
抛出:
RasterFormatException - 如果指定区域不包含在此 BufferedImage 中。
如果你的需求可以接受子图与源图共享数据数组,直接调用BufferedImage类的getSubimage方法,应该是最快的
[code="java"]
public static BufferedImage getSubImage(BufferedImage src, int x, int y, int width, int height) {
BufferedImage dest;
int imageType = src.getType();
if (imageType == BufferedImage.TYPE_CUSTOM)
dest = ImageUtils.newBufferedImage(src.getColorModel(), width, height);
else
dest = new BufferedImage(width, height, imageType);
AffineTransform xform = AffineTransform.getTranslateInstance(-x, -y);
BufferedImageOp op = new AffineTransformOp(xform, null);
dest = op.filter(src, dest);
return dest;
}[/code]
public static BufferedImage newBufferedImage(ColorModel dstCM, int width, int height) {
return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(width, height), dstCM
.isAlphaPremultiplied(), null);
}