val pixels = IntBuffer.allocate(screenWidth * screenHeight)
GLES20.glReadPixels(0, 0, screenWidth, screenHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixels )
val stitchBmp = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888)
stitchBmp.copyPixelsFromBuffer(pixels)
错误
- 使用IntBuffer而不是ByteBuffer
- 之前用ByteBuffer(screenWidth * screenHeight *4)发现不可以,这个方法是 glReadPixels 数组是像素的大小,而不是像素分量的大小
源码
https://github.com/AlbertSnow/GraphicDemo