在Android的表面纹理相机preVIEW
这是我的情况:我想,当有人在锁屏放入了不正确的密码,采取从前置摄像头的画面。基本上,我需要能够拍照出来的前凸轮没有preVIEW。
This is my scenario: I am trying to take a picture from the front camera when someone puts in the incorrect password in the lock screen. Basically, I need to be able to take a picture out of the front cam without a preview.
很多google搜索后,我想通了,做的方式是OpenGL和表面纹理。你直接在相机preVIEW到表面纹理,后来提取此纹理的图片不知何故。我发现了这一点,从以下资源:
After much googling, I figured out that the way to do it is opengl and SurfaceTexture. You direct the camera preview to a SurfaceTexture, and later extract the picture from this texture somehow. I found this out from the following resources:
- http://stackoverflow.com/a/10776349/902572 (建议1)
- 的http://www.freelancer.com/projects/Android-opengl/Android-OpenGL-App-Access-Raw.html,这是相同的:(1)
- https://groups.google.com/forum/#!专题/ Android的开发者/ U5RXFGpAHPE (见罗曼对11年12月22日文章)
- http://stackoverflow.com/a/10776349/902572 (suggestion 1)
- http://www.freelancer.com/projects/Android-opengl/Android-OpenGL-App-Access-Raw.html, which is the same as (1)
- https://groups.google.com/forum/#!topic/android-developers/U5RXFGpAHPE (See Romain's post on 12/22/11)
我明白了什么是必须要做的,但我一直无法正确地把它们放到code,因为我是新来的OpenGL。
I understand what is to be done, but i have been unable to correctly put them into code, as I am new to opengl.
借助 CameraToMpegTest 例子有你最需要的东西,但它远远超出了你的使用情况(它记录一系列preVIEW帧作为视频)。
The CameraToMpegTest example has most of what you need, though it goes well beyond your use case (it's recording a series of preview frames as a video).
你需要什么剩下的就是在 ExtractMpegFramesTest 。特别是,要渲染到屏幕外的pbuffer(而不是媒体codeC
连接codeR输入表面),并且可以保存pbuffer的内容使用PNG文件 saveFrame()
。
The rest of what you need is in ExtractMpegFramesTest. In particular, you want to render to an offscreen pbuffer (rather than a MediaCodec
encoder input surface), and you can save the pbuffer contents as a PNG file using saveFrame()
.
以上是写成小的无头的测试用例。你可以看到类似code在一个完整的应用程序在 Grafika 。
The above are written as small "headless" test cases. You can see similar code in a full app in Grafika.