我想在 Java 中模糊缓冲图像,而不需要特殊的“模糊 api”。现在我找到了这个页面并编写了这段代码:
public int[][] filter(int[][] matrix)
{
float[] blurmatrix = {
0.111f, 0.111f, 0.111f,
0.111f, 0.111f, 0.111f,
0.111f, 0.111f, 0.111f,
};
int[][] returnMatrix = new int[matrix.length][matrix[0].length];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
returnMatrix[i][j]=matrix[i][j];
for(int k=0;k<blurmatrix.length;k++)
{
float blurPixel= blurmatrix[k];
int newPixel= (int) (returnMatrix[i][j]*blurPixel);
returnMatrix[i][j]= newPixel;
}
}
}
return returnMatrix;
}
int 矩阵来自此方法:
public int[][] getMatrixOfImage(BufferedImage bufferedImage) {
int width = bufferedImage.getWidth(null);
int height = bufferedImage.getHeight(null);
int[][] retrunMatrix = new int[width][height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
retrunMatrix[i][j] = bufferedImage.getRGB(i, j);
}
}
return retrunMatrix;
}
但它想要工作,有什么问题?
谢谢!
更新
问题是,结果不是应该的。当我有这个模糊矩阵时:
float[] blurmatrix = {
10.111f, 0.111f, 0.111f,
0.111f, 50.111f, 0.111f,
0.111f, 0.111f, 10.111f,
};
我得到这个结果: http: //img854.imageshack.us/img854/541/2qw7.png 当我有这个模糊矩阵时:
float[] blurmatrix = {
0.111f, 0.111f, 0.111f,
0.111f, 0.111f, 0.111f,
0.111f, 0.111f, 0.111f,
};
图片被删除。