Created
August 30, 2012 03:42
-
-
Save teppeihomma/3522079 to your computer and use it in GitHub Desktop.
glReadPixelsからBitmapへの画像取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ByteBufferに読み込み | |
ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4); | |
gl10.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buffer); | |
// 上下逆なので、上下反転 | |
byte[] tmp1 = new byte[width * 4]; | |
byte[] tmp2 = new byte[width * 4]; | |
int h = (int) height / 2; | |
for (int y = 0; y < h; y++) { | |
buffer.position(y * width * 4); | |
buffer.get(tmp1, 0, tmp1.length); | |
buffer.position((height - 1 - y) * width * 4); | |
buffer.get(tmp2, 0, tmp2.length); | |
buffer.position((height - 1 - y) * width * 4); | |
buffer.put(tmp1); | |
buffer.position(y * width * 4); | |
buffer.put(tmp2); | |
} | |
buffer.position(0); | |
tmp1 = tmp2 = null; | |
// Bitmapの作成 | |
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | |
bitmap.copyPixelsFromBuffer(buffer); | |
// 後片付け | |
buffer = null; | |
System.gc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment