android opengl 获取bitmap 数据
2014-03-03 10:02
513 查看
视频截图或游戏界面截图 要求获取位图数据 ,然后本地保存图片。
方式1:测试通过
方法2 :http://www.eoeandroid.com/thread-56476-1-1.html
方法3:http://www.oschina.net/code/snippet_729469_19233
后面两种没有测试,先收藏起来。
方式1:测试通过
int screenshotSize = this.getWidth() * this.getHeight(); ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4); bb.order(ByteOrder.nativeOrder()); gl.glReadPixels(0, 0, this.getWidth(), this.getHeight(), GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb); int pixelsBuffer[] = new int[screenshotSize]; bb.asIntBuffer().get(pixelsBuffer); bb = null; Bitmap bitmap = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.RGB_565); bitmap.setPixels(pixelsBuffer, screenshotSize-this.getWidth(), -this.getWidth(), 0, 0, this.getWidth(), this.getHeight()); pixelsBuffer = null; short sBuffer[] = new short[screenshotSize]; ShortBuffer sb = ShortBuffer.wrap(sBuffer); bitmap.copyPixelsToBuffer(sb); //Making created bitmap (from OpenGL points) compatible with Android bitmap for (int i = 0; i < screenshotSize; ++i) { short v = sBuffer[i]; sBuffer[i] = (short) (((v&0x1f) << 11) | (v&0x7e0) | ((v&0xf800) >> 11)); } sb.rewind(); bitmap.copyPixelsFromBuffer(sb); screenshotCallback.onScreenshot(bitmap); public abstract class AsynScreenshotCallback { /** * * 异步截图回调 * @param bitmap 截图的位图对象 * @throws */ public abstract void onScreenshot(Bitmap bitmap); }
方法2 :http://www.eoeandroid.com/thread-56476-1-1.html
方法3:http://www.oschina.net/code/snippet_729469_19233
后面两种没有测试,先收藏起来。
相关文章推荐
- Android - 获取网络数据,Bitmap,ANR,主线程模型,消息机制,UserAgent,乱码问题,xml生成与解析,JSON解析,MVC,SmartImageView
- Android数据存储:获取网络图片把图片保存到SD卡中并从SDk卡中读取(通过Bitmap方法)
- android HTTP获取JSON数据笔记
- Android直连MySql异步获取数据
- Android使用Firebase无法获取ArrayList数据
- android超级课程表原理(各大高校教务平台的数据获取原理)
- Android 小笔记 Uri获取绝对路径 、路径转Bitmap、获取屏幕截图
- Delphi获取Android下GPS的NMEA 0183数据
- android实现从servlet获取数据
- 根据BITMAPINFO获取位图数据
- C#获取Bitmap图中的裸数据
- android 获取资源文件 r.drawable中的图片转换为drawable、bitmap
- 【Android】Glide 如何获取 bitmap 来进行再处理(比如处理长图的显示)
- Android -- 获取接口数据的三个方法
- android客户端从服务器端获取json数据并解析的实现代码
- Android基础 -- Activity之间传递数据(bitmap和map对象)
- Android手持机扫码获取数据
- android 获取资源文件 r.drawable中的图片转换为drawable、bitmap
- android 获取网络连接(登陆验证+获取数据)
- Android如何获取系统联系人数据?