模糊的黑色矩形

时间:2013-10-13 16:04:59

标签: java

我想模糊我图像的一部分,所以我使用Kernel和BufferedImageOp编写了一些代码。

private void blurPartially(BufferedImage ss, int x, int y, int w, int h, Graphics gz) {
    BufferedImage bufferedImage = deepCopy(ss).getSubimage(x, y, w, h);

    Kernel kernel = new Kernel(3, 3, new float[] { 0.111f, 0.111f, 0.111f,
            0.111f, 0.111f, 0.111f, 0.111f, 0.111f, 0.111f });
    BufferedImageOp op = new ConvolveOp(kernel);
    gz.drawImage(op.filter(bufferedImage, null), x, y, w, h, null);
    repaint();
}
private BufferedImage deepCopy(BufferedImage bi) {
        ColorModel cm = bi.getColorModel();
        boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
        WritableRaster raster = bi.copyData(null);
        return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
    }

但它在模糊区域周围留下了一些奇怪的矩形:

rectangles around blur area

我无法找到导致此问题的任何合理代码。

0 个答案:

没有答案