0

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?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    check this https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-on-android – darwin Jun 27 '22 at 05:06
  • 1
    Does this answer your question? [How to programmatically take a screenshot on Android?](https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-on-android) – darwin Jun 27 '22 at 05:07

0 Answers0