安卓(Android) 怎么配置相机参数(Camera Parameters)

2019年10月27日22:05:54安卓(Android) 怎么配置相机参数(Camera Parameters)已关闭评论 657 1500字阅读5分0秒

1.简介

安卓(Android) 怎么配置相机参数(Camera Parameters)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Build;
import android.util.Log;
import android.view.Surface;

public class Main{
    private static final String CAMERA_PARAM_ORIENTATION = "orientation";
    private static final String CAMERA_PARAM_LANDSCAPE = "landscape";
    private static final String CAMERA_PARAM_PORTRAIT = "portrait";
    private static Camera mCamera;
    private static int mCameraAngle;
    public static void configureCameraParameters(Context context,
            int rotation) {
        Parameters cameraParams = mCamera.getParameters();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) { 
            if (isPortrait(context)) {
                cameraParams.set(CAMERA_PARAM_ORIENTATION,
                        CAMERA_PARAM_PORTRAIT);
                mCameraAngle = 90;
            } else {
                cameraParams.set(CAMERA_PARAM_ORIENTATION,
                        CAMERA_PARAM_LANDSCAPE);
                mCameraAngle = 0;
            }
        } else { 
            switch (rotation) {
            case Surface.ROTATION_0: 
                mCameraAngle = 90; 
                break;
            case Surface.ROTATION_90:
                mCameraAngle = 0;
                break;
            case Surface.ROTATION_180:
                mCameraAngle = 270;
                break;
            case Surface.ROTATION_270:
                mCameraAngle = 180;
                
                break;
            default:
                mCameraAngle = 90;
                break;
            }
            Log.d(LogUtil.TAG, "angle: " + mCameraAngle);
            mCamera.setDisplayOrientation(mCameraAngle);
        }

        cameraParams.setRecordingHint(true);
        mCamera.setParameters(cameraParams);
    }
    public static boolean isPortrait(Context context) {
        return (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
    }
}

 
继续阅读
编程十万个怎么办