如何采取surfaceview的快照? [英] How to take snapshot of surfaceview?

查看:886
本文介绍了如何采取surfaceview的快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在使用Android应用程序中的H264视频渲染工作 SurfaceView 。它有一个功能,拍摄快照,同时呈现在表面观看视频。每当我拍摄快照,我得到的透明/黑色屏幕只。我使用 getDrawingCache()方法来捕获只返回一个空值的屏幕。我用的是低于code捕捉的屏幕。

  SurfaceView mSUrfaceView =新SurfaceView(本); //成员变量如果(mSUrfaceView!= NULL)
  mSUrfaceView.setDrawingCacheEnabled(真);上呈现surfaceview //视频后我启用了绘图缓存位图BM = mSUrfaceView.getDrawingCache(); //返回NULL


解决方案

除非你与画布渲染H.264视频帧的软件安装到视图,绘图缓存的做法是行不通的(例如参见<一个href=\"http://stackoverflow.com/questions/25086263/take-screenshot-of-surfaceview/25086739#25086739\">this回答)。

您无法读取从SurfaceView的表面部分像素。基本的问题是,一个面是​​具有生产者 - 消费者接口缓冲器的队列中,和应用程式是在生产者侧。消费者,通常是系统合成器(SurfaceFlinger的),是能够捕捉的屏幕截图,因为它是在管道的另一端。

要抢快照,而渲染视频,你可以渲染视频帧到<一个href=\"http://developer.android.com/reference/android/graphics/SurfaceTexture.html\">SurfaceTexture,您的应用程序中同时提供了生产者和消费者。然后,您可以呈现质感与GLES显示屏,可选抓住与 glReadPixels()像素的快照。

借助 Grafika 应用演示各个部分,虽然没有活动的专门解决您的问题。例如,连续拍摄指示相机preVIEW到表面纹理,然后使得它两次(一次显示,一旦视频编码),这类似于你想要做什么。该GLES实用工具类包括<一个href=\"https://github.com/google/grafika/blob/master/src/com/android/grafika/gles/EglSurfaceBase.java\">saveFrame()函数,演示如何使用 glReadPixels()来创建位图。

又见了Android 系统级图形架构文件。

Am working in H264 video rendering in Android application using SurfaceView. It has one feature to take snapshot while rendering the video on surface view. Whenever I take a snapshot, I get the Transparent/Black screen only. I use getDrawingCache() method to capture the screen that returns a null value only. I use the below code to capture the screen.

SurfaceView mSUrfaceView = new SurfaceView(this); //Member variable

if(mSUrfaceView!=null)
  mSUrfaceView.setDrawingCacheEnabled(true); // After video render on surfaceview i enable the drawing cache

Bitmap bm = mSUrfaceView.getDrawingCache(); // return null  

解决方案

Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).

You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.

To grab snapshots while rendering video you can render video frames to a SurfaceTexture, which provides both producer and consumer within your app process. You can then render the texture for display with GLES, optionally grabbing pixels with glReadPixels() for the snapshot.

The Grafika app demonstrates various pieces, though none of the activities specifically solves your problem. For example, "continuous capture" directs the camera preview to a SurfaceTexture and then renders it twice (once for display, once for video encoding), which is similar to what you want to do. The GLES utility classes include a saveFrame() function that shows how to use glReadPixels() to create a bitmap.

See also the Android System-Level Graphics Architecture document.

这篇关于如何采取surfaceview的快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆