将图像叠加到相机预览 SurfaceView 上
我有一个用于绘制图像的 SurfaceView,我想将它们叠加到手机摄像头的实时反馈上。
目前,包含图像的 SurfaceView 具有白色背景,但如果我要将它们覆盖到手机的摄像头源上,它们必须是透明的。相机和动画绘制不能在同一个 SurfaceView 上完成。
追求使用涉及管理相机和绘制图像的多个视图的最佳课程是什么?是否可以使 SurfaceView 透明?
I have a SurfaceView
that is being used to draw images, and I would like to overlay them onto a live-feed from the phone's camera.
Currently, the SurfaceView
that contains the images have a white-background, but if I were to overlay them onto the phone's camera feed, they would have to be transparent. The camera and animation drawing cannot be done on the same SurfaceView
.
What is the best course to pursue the use of multiple views that involve managing the camera and drawing images? Is it possible to make a SurfaceView
transparent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我是这样做的……我希望有人发现它有用,尽管高通 AR 的东西已经过时了……它可能已经过时了……
哦,基本上,它的作用是——从 Android 示例中生成两个时髦的立方体,引入的附加功能是触摸事件,尽管旋转向量偏离了很多——无论如何只是为了演示目的,当然立方体覆盖在顶部可以在屏幕上移动的相机预览。
TouchSurfaceView 的定义如下:
CubeRenderer 的给出方式为:
最后 Cube 本身的给出方式为:
希望有人发现这很有用...
Well here's how I did it ... I hope somebody finds it useful though the Qualcomm AR stuff is out.. it might be obselete..
oh and basically what this does is -- generate two funky cubes from that Android Example, additional functionality introduced are the touch events, though the rotational vectors are off by a lot-- just for a demonstration purpose anyway and ofcourse the cubes overlaid on top of the camera preview which can be moved on a screen..
The TouchSurfaceView is defined below:
And the CubeRenderer is given by:
And finally the Cube itself is given by:
Well hope somebody finds this useful...
我通过以下方法取得了成功。
首先创建一个布局 xml 文件,如下所示(注意两个视图的顺序):
OverlayView
是SurfaceView
的子类,具有绘图和动画线程实现。另一个 SurfaceView 将是处理相机预览的表面。在onCreate
内部,您应该像这样设置视图:您应该将
SurfaceHolder.Callback
实现添加到mView< 的
SurfaceHolder
/code> 处理动画线程。在子类中实现此功能并使用动画/绘图线程的示例可以在此处的旧 LunarLander 示例中找到:http://developer.android.com /resources/samples/LunarLander/src/com/example/android/lunarlander/LunarView.html
除此之外,您还可以按照与此示例相同的方式设置相机 SurfaceView:
http://developer.android .com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
I have had success with the following approach.
First make a layout xml file that looks something like this (note the order of the two views):
OverlayView
is a subclass ofSurfaceView
with the drawing and animation thread implementations. The other SurfaceView will be the surface that handles the Camera preview. Inside ofonCreate
you should set up your views like this:You should add a
SurfaceHolder.Callback
implementation to theSurfaceHolder
ofmView
that handles the animation thread. An example of implementing this within the subclass and using animation/drawing threads can be found in the old LunarLander example here:http://developer.android.com/resources/samples/LunarLander/src/com/example/android/lunarlander/LunarView.html
Besides that you set up the camera SurfaceView the same way as this example:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
我也在做增强应用程序并遇到了与您遇到的相同问题。关于如何正确解决该问题的信息很少。但我发现了一个名为 mixare 的框架 - 它允许您为 Android 创建 AR 应用程序。你绝对应该看看它源代码 - 它看起来很有前途。希望这会对您有所帮助。
I'm doing augmented application too and hit the same problem you hit. There is very few information on how to solve it right. But I found a framework called mixare - it allow you to create AR app for android. You should definitely look at it source - it looks pretty promising. Hope this will help you.
这段代码可能有帮助吗?`
MIght this code help?`
刚把手机升级到 4.0.4 后发现有点奇怪的余震。我在全屏相机预览上有一个半透明的 gl 全屏覆盖,它在早期的 ics 版本上工作得非常愉快(我认为它是 4.0.3,但不确定)。升级到 4.0.4 后,预览有点混乱,相机图像的任何较亮部分都显示出迷幻的主要颜色区域(较暗部分看起来还不错)。最终发现将glclearcolor从0.5,0.5,0.5改为0,0,0,0。 0 整理一下。
看起来,即使在 gl 叠加层未使用的部分上 alpha 为零,混合函数仍然考虑到灰色 gl 背景。
Just found a slightly strange aftershock from upgrading my handset to 4.0.4. I have a translucent gl whole screen overlay on a whole screen camera preview, which worked quite happily on an earlier ics build (I think it was 4.0.3, but not certain). After upgrading to 4.0.4, the preview went a bit haywire, with the camera image showing psychedelic primary areas of colour on any of the brighter parts of the camera image (darker parts looked OK). Eventually found that changing glclearcolour to 0,0,0,0 from 0.5, 0.5, 0.5. 0 sorted it out.
It seems that even though the alpha was zero on the unused parts of the gl overlay, the blending function was still taking account of the grey gl background.