I implemented the below function to capture a screenshot of the current view of my app.
val v = this.view!!
val w = v.width
val h = v.height
val bitmapBuffer = IntArray(w * h)
val bitmapSource = IntArray(w * h)
val intBuffer: IntBuffer = IntBuffer.wrap(bitmapBuffer)
intBuffer.position(0)
glReadPixels(0, 0, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer)
var offset1: Int
var offset2: Int
for (i in 0 until h) {
offset1 = i * w
offset2 = (h - i - 1) * w
for (j in 0 until w) {
val texturePixel = bitmapBuffer[offset1 + j]
val blue = texturePixel shr 16 and 0xff
val red = texturePixel shl 16 and 0x00ff0000
val pixel = texturePixel and -0xff0100 or red or blue
bitmapSource[offset2 + j] = pixel
}
}
val bit: Bitmap = Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888)
But I am getting a full black screenshot. Is that due to the GLES version I am using?