将相机预览保存到位图
我需要一些帮助才能让我的相机正常工作。
我想做的是让用户拍摄一张照片,然后将其在另一个活动中用作视图的背景。重要的是不要有任何倾斜,理想情况下图像将以尽可能高的分辨率填充整个背景。
我花了很长时间试图让相机输出的图片正确定向并与显示器保持相同的方向。所以我花了一些时间来思考我到底需要做什么,我认为我根本不需要正常保存的图像。
我想到的是,我需要一个表面视图来显示预览,以及一些文本和捕获按钮的覆盖层。当用户“拍照”时,它应该自动对焦,然后我需要将预览(在屏幕覆盖层下)捕获到位图以在其他活动中使用。
*我是否应该为预览扩展 SurfaceView 并将其添加到包含叠加层的 XML 布局中?
*如何将 SurfaceView 的图像保存为位图?
谢谢。
I need a little help with getting my camera to work right.
What I'm trying to do is have the user take a picture that will then be used in another activity as the view's background. It is important not to have any skewing, and ideally the image would fill the entire background with the highest resolution possible.
I've been having a heck of a time trying to get the outputted picture of my camera to be oriented properly and be the same aspect of the display. So I took some time to think of exactly what I needed to do, and I don't think I need the normal saved image at all.
What I came up with is that I need a surface view to display the preview, and an overlay for some text and a capture button. When the user "takes the picture" it should autofocus, and then I need to capture the preview (under the screen overlays) to a bitmap to use in the other activity.
*Should I extend a SurfaceView for my preview and add it to a XML layout that contains the overlays?
*How do I save the SurfaceView's image to a bitmap?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
马特,
一个基本问题,请原谅我的天真,通过 Intent 使用 Android 内置摄像头不是更容易吗?这是可行的,我以前做过。
Matt,
One basic question ,and excuse my naivety, wouldnt it just be easier to use the built in camera to the Android through an Intent? It is doable, I've done it before.
显然,没有很好的方法将预览帧的图像格式转换为 jpeg,因此我最终通过检查每个相机支持的分辨率并获得与屏幕方面最接近的匹配来选择相机拍摄的尺寸以最高分辨率。
因为camera.setRotation方法似乎没有做任何事情,所以如果我处于纵向模式,我只是用矩阵将图像旋转90°,然后将其保存到卡上。
Apparently, there is no good way to convert the image format of the preview frames to a jpeg, so I ended up selecting the size for the camera to take by going through each of the camera's supported resolutions and getting the closest match the the screen aspect with the highest resolution.
Because the camera.setRotation method doesn't seem to do anything, I just rotate the image 90 with a matrix before saving it to the card if I am in portrait mode.