Skip to content
Snippets Groups Projects
Commit f6ce4177 authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#9 Screenshot using OpenGl buffer

parent 15fee58e
Branches
Tags
No related merge requests found
......@@ -36,14 +36,18 @@ public class AndroidLauncher extends AndroidApplication {
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
try {
Bitmap sb = Bitmap.createBitmap(screen, width, height, Bitmap.Config.ARGB_8888);
for (int i = 0; i < screen.length; ++i) {
// The alpha and green channels' positions are preserved while the red and blue are swapped
screen[i] = ((screen[i] & 0xff00ff00)) | ((screen[i] & 0x000000ff) << 16) | ((screen[i] & 0x00ff0000) >> 16);
}
Bitmap sb = Bitmap.createBitmap(screen, width, height, Bitmap.Config.RGB_565);
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath();
File dir = new File(file_path);
dir.mkdirs();
File file = new File(dir, "screenshot_tablexia_" + System.currentTimeMillis() + ".png");
FileOutputStream fOut = new FileOutputStream(file);
sb.compress(Bitmap.CompressFormat.PNG, 85, fOut);
sb.compress(Bitmap.CompressFormat.PNG, 100, fOut);
sb.recycle();
fOut.flush();
fOut.close();
......
......@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.GL30;
import net.engio.mbassy.listener.Handler;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Locale;
import cz.nic.tablexia.bus.ApplicationBus;
......@@ -179,24 +180,10 @@ public class Tablexia extends TablexiaApplication {
int height = Gdx.graphics.getHeight();
int bt[] = new int[width * height];
ByteBuffer pbuf = ByteBuffer.allocateDirect(width * height * 4);
//pbuf.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer pbuf = ByteBuffer.allocateDirect(width * height * 4);
pbuf.order(ByteOrder.nativeOrder());
Gdx.gl.glReadPixels(0, 0, width, height, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE, pbuf);
for (int i = 0; i < height; i++) {//remember, that OpenGL bitmap is incompatible with Android bitmap
//and so, some correction need.
for (int j = 0; j < width; j++) {
int pr = pbuf.get(4 * i * j + j);
int pg = pbuf.get(4 * i * j + j + 1);
int pb = pbuf.get(4 * i * j + j + 2);
//int pa = pbuf.get(4 * i * j + j + 3);
int pa = 1;
int color = (pa << 24) | (pr << 16) | (pg << 8) | pb;
bt[(i * j) + j] = color;
}
}
pbuf.asIntBuffer().get(bt);
if (listener != null) {
listener.screenshotTaken(bt);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment