如何压缩LibGDX Pixmap?我想将它保存在磁盘上,但它使用大约4MB,这是很多东西,需要永远保存它。
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
FileHandle screenshot = Gdx.files.local("something.png");
PixmapIO.writePNG(screenshot, pixmap);
我看到有一个PixmapIO.writeCIM
,它非常快,输出很小。
我可以在Android中显示something.cim文件吗? docu表示,cim只能在libgdx中使用。认为这是旧的文档,也许有新的东西?
答案 0 :(得分:3)
http://badlogicgames.com/forum/viewtopic.php?f=11&t=8947
int w = p.getWidth();
int h = p.getHeight();
int[] pixels = new int[w * h];
for (int y=0; y<h; y++) {
for (int x=0; x<w; x++) {
//convert RGBA to RGB
int value = p.getPixel(x, y);
int R = ((value & 0xff000000) >>> 24);
int G = ((value & 0x00ff0000) >>> 16);
int B = ((value & 0x0000ff00) >>> 8);
int A = ((value & 0x000000ff));
int i = x + (y * w);
pixels[ i ] = (A << 24) | (R << 16) | (G << 8) | B;
}
}
Bitmap b = Bitmap.createBitmap(pixels, w, h, Config.ARGB_8888);
b.compress(CompressFormat.JPEG, quality, handle.write(false));