我一直在研究 java 和 libgdx 的高斯模糊。它主要工作...
问题是红色值在大多数情况下等于 -1,而不是像 255 这样的值。我搜索了很多论坛,但他们没有解决这个问题。我还注意到大多数人使用 ARGB8888,但 badlogics 库没有 ARGB8888 格式它有 RGBA8888 格式。我还在网站上搜索了 RGBA8888 如何以位存储其信息,我有些了解,但不足以解决问题。
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.badlogic.gdx.utils.BufferUtils;
import com.badlogic.gdx.utils.ScreenUtils;
import java.awt.image.ConvolveOp;
import java.nio.ByteBuffer;
public class ScreenCapture {
public void capture(){
float output = 0;
int[] all = new int[11];
Pixmap originalPixmap = new Pixmap(Gdx.files.internal("graphics/menu/test.png"));
Pixmap pixmapVertical = new Pixmap(originalPixmap.getWidth(), originalPixmap.getHeight(), Pixmap.Format.RGBA8888);
Pixmap pixmap = new Pixmap(pixmapVertical.getWidth(), pixmapVertical.getHeight(), Pixmap.Format.RGBA8888);
for (int y = 0;y < originalPixmap.getHeight();y++){
for (int x = 0;x < originalPixmap.getWidth();x++){
for (int i = -5; i < 5; i++) {
all[i+5] = originalPixmap.getPixel(x+i, y);
}
pixmapVertical.setColor(blur(all));
pixmapVertical.drawPixel(x, y);
}
}
for (int x = 0;x < pixmapVertical.getWidth();x++){
for (int y = 0;y < pixmapVertical.getHeight();y++){
for (int i = -5; i < 5; i++) {
all[i+5] = pixmapVertical.getPixel(x, y+i);
}
pixmap.setColor(blur(all));
pixmap.drawPixel(x, y);
}
}
PixmapIO.writePNG(Gdx.files.local("screen.png"), pixmap);
originalPixmap.dispose();
pixmapVertical.dispose();
pixmap.dispose();
int rgb = 0xffffffff;
int test = ((rgb & 0xff000000) >> 24);
System.out.println(test);
}
private int blur(int[] all){
float[] weight = {0.0093f, 0.028002f, 0.065984f, 0.121703f, 0.175713f, 0.198596f, 0.175713f, 0.121703f, 0.065984f, 0.028002f, 0.0093f};
float r = 0;
float g = 0;
float b = 0;
float a = 0;
for (int i = 0; i < 11; i++){
b += ( ((all[i] & 0x0000ff00)>>8)*weight[i]);
r += ( ( (all[i] & 0xff000000)>>24 )*weight[i]);
g += ( ((all[i] & 0x00ff0000)>>16)*weight[i]);
a += ( ((all[i] & 0x000000ff))*weight[i]);
}
return (((int) r << 24 | (int)g << 16 | (int)b << 8 | (int)a ));
}
}