【Android】textureToBitmap

网友投稿 529 2022-11-14

【Android】textureToBitmap

【Android】textureToBitmap

【Android】textureToBitmap

/** * textureToBitmap * * @param width 宽度 * @param height 高度 * @param texIn textureId */ private void textureToBitmap(int width, int height, int texIn) { int[] oldFboId = new int[1]; GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, IntBuffer.wrap(oldFboId)); int[] framebuffers = new int[1]; GLES20.glGenFramebuffers(1, framebuffers, 0); int framebufferId = framebuffers[0]; GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebufferId); int[] renderbuffers = new int[1]; GLES20.glGenRenderbuffers(1, renderbuffers, 0); int renderId = renderbuffers[0]; GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderId); GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texIn, 0); GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderId); if (GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER) != GLES20.GL_FRAMEBUFFER_COMPLETE) { } ByteBuffer rgbaBuf = ByteBuffer.allocateDirect(width * height * 4); rgbaBuf.position(0); GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, rgbaBuf); rgbaBuf.rewind(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(rgbaBuf); // final Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); Log.e("ljc", "textureToBitmap"); GLES20.glDeleteRenderbuffers(1, IntBuffer.wrap(framebuffers)); GLES20.glDeleteFramebuffers(1, IntBuffer.allocate(framebufferId)); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, oldFboId[0]); }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于springBoot yml文件的list读取问题总结(亲测)
下一篇:LeetCode(算法)- 154. 寻找旋转排序数组中的最小值 II
相关文章

 发表评论

暂时没有评论,来抢沙发吧~