采取在Android 2.2的朝前的照片和后置摄像头 [英] Take photos from front-facing and rear cameras on android 2.2

查看:162
本文介绍了采取在Android 2.2的朝前的照片和后置摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个应用程序(在2.2版)使用相机拍摄的照片。

I'm designing an app (on version 2.2) that use the camera to capture photos.

我从 http://developer.android.com/sdk/android-2.3阅读html的该版本2.3及以上的有多个摄像头的支持。但我还是有点困惑,因为当相机启动时,它通常有一个按钮,用户可以单击前置和后置摄像头之间切换,对不对?

I read from http://developer.android.com/sdk/android-2.3.html that version 2.3 and above have multiple cameras support. But i'm still a bit confused because when the camera is launched, it normally have a button that the user can click to switch between front-facing and rear cameras, right?

2.2没有这个开关?

2.2 doesn't have this switch?

我希望用户能够同时使用前部和后部摄像机。是否有可能在2.2版本或者我应该使用2.3及以上?

I want the user to be able to use both front and rear cameras. Is it possible on version 2.2 or should I use 2.3 and above?

推荐答案

是的,2.2只能管理后置摄像头。
对于正面摄像头,你需要升级到2.3 +

Yes, 2.2 can only manage rear camera. For frontal camera you need to upgrade to 2.3+.

private int getBestCameraId() {

        PackageManager pm = m_mainThreadContext.getPackageManager();

        try {
            if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
                Log.i(TAG, "Phone has a frontal camera.");
                return Camera.CameraInfo.CAMERA_FACING_FRONT;
            } else {
                Log.i(TAG, "Phone has only rear camera.");
                return Camera.CameraInfo.CAMERA_FACING_BACK;
                }
        } catch (Exception e) {
                return Camera.CameraInfo.CAMERA_FACING_BACK;
    }

}

有了这个简单的功能,它检查手机是否有正面或后置摄像头,并返回最佳。
返回可以在Camera.open(ID)一起使用的ID来选择所需要的摄像机

With this simple function it check whether the phone has a frontal or rear camera, and return the best. The id returned can be used in the Camera.open(id) to select the desired camera.

如果你的清单,你写的:

If in your Manifest you write:

<uses-sdk android:minSdkVersion="8" />

和你发展与库2.3(或+)项目,我已经张贴像一个魅力的作品的功能!
我在相机项目中使用,所以请相信我;)

and you develop your project with libraries 2.3 (or +), the function i have posted works like a charm! I've used in a camera project, so trust me ;)

这篇关于采取在Android 2.2的朝前的照片和后置摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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