1

编辑我正在使用 Eclipse ADT 包,但是当我尝试在上面建议的答案中导入库时,它不起作用。

我正在使用 LibGDX 和 Java (90-99% java) 的组合来模糊图像。模糊有效,但截屏、保存、访问、模糊、保存和重新访问需要将近一秒钟的时间。我不能做太多的预处理,因为它需要一个游戏的截图来模糊。这是我目前用于模糊的内容:(如果您需要查看它们,我会放上绘图和屏幕截图,但我认为问题在于 800x480 png 的模糊。)

import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;


public class Blur {
    private static BufferedImage mshi;
    private BufferedImage databuf;
    private static int blurRad = 300;

    public static void createBlur(FileHandle file) throws IOException {
        mshi = ImageIO.read(file.file());
        BufferedImage databuf = new BufferedImage(mshi.getWidth(null),
                mshi.getHeight(null),
                BufferedImage.TYPE_INT_BGR);

        java.awt.Graphics g = databuf.getGraphics();
        g.drawImage(mshi, 455, 255, null);

        float[] blurKernel = new float[blurRad*blurRad];
        for(int i =0; i<blurRad*blurRad; i++) {
            blurKernel[i] = 1.0f/256.0f;
        }

        BufferedImageOp op = new ConvolveOp( new Kernel(20, 20, blurKernel), ConvolveOp.EDGE_ZERO_FILL, null );
        mshi = op.filter(mshi, databuf);

        g.dispose();    

        File outputfile = Gdx.files.local("Blur.png").file();
        ImageIO.write(mshi, "png", outputfile);
    }
}
4

0 回答 0