获取从SurfaceView框架 [英] Getting a frame from SurfaceView
问题描述
现在我遇到的困难是采取SurfaceView的屏幕截图。任何人都可以请帮助?
The difficulty I am having now is to take a screenshot of the SurfaceView. Could anyone please help?
我的团队正在做一个Android项目中,我们使用媒体codeC脱$ C C视频输入$,并呈现进到表面。 活动工具
My team is doing an Android project where we use MediaCodec to decode the video feed and render the feed onto a Surface. The activity implements
SurfaceHolder.Callback
然后,我们创建了一个SurfaceView,并添加回调:
Then we created a SurfaceView and add the Callback:
mySurfaveView.getHolder().addCallback(this);
然后,我们开始c。在视频输入(我们有确实的去code的方法)
Then we start decode the video feed in (we have a method that does the decode)
surfaceChanged(SurfaceHolder holder, int format, int width, int height)
视频做工精细,现在我想盘点一下被渲染到SurfaceView截图。我尝试了好几种方法可以做到这一点,但我没有成功。以下是我曾尝试:
The video work fine, now I want to take screenshot of what gets rendered onto the SurfaceView. I have tried several ways to do this, but I didn't succeed. Following are what I have tried:
- 我已经厌倦了越来越rootView的drawingcache。
- 在尝试直接从媒体codeC获得帧。
- 试过draw()方法绘制在画布上。
截至目前,我特林创建一个自定义的SurfaceView和覆盖的OnDraw方法那里。不过,我从来没有创建一个自定义的SurfaceView。我是在正确的方向?
As of now I am tring to create a custom SurfaceView and override the onDraw method there. However, I have never created a custom SurfaceView. Am I on the right direction?
请帮助。谢谢!
推荐答案
您无法捕捉一个SurfaceView,如本<一个解释href="http://stackoverflow.com/questions/27817577/android-take-screenshot-of-surface-view-shows-black-screen">other问题。
You can't capture a SurfaceView, as explained in this other question.
SurfaceViews很少会想覆盖的OnDraw()
。一般情况下SurfaceView的视图部分是透明的洞。
SurfaceViews will rarely want to override onDraw()
. Generally the View part of the SurfaceView is a transparent hole.
有关媒体codeC输出的特殊情况下,你有两个选择。您可以直接输出到 的表面纹理,然后渲染视频帧使用OpenGL ES的两倍。一旦到了SurfaceView显示,一旦到一个离屏缓冲,从中可以捕捉到像素。
For the specific case of MediaCodec output, you have a couple of choices. You can direct the output to a SurfaceTexture, and then render the video frame twice using OpenGL ES. Once to the SurfaceView for display, once to an off-screen buffer from which you can capture the pixels.
另一种方法是用一个 TextureView 的取代SurfaceView,和然后使用 getBitmap()
通话抢到视频帧。
Another approach is to replace the SurfaceView with a TextureView, and then use the getBitmap()
call to grab video frames.
各种实例中可以找到 Grafika 。
这篇关于获取从SurfaceView框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!