一、Camera.Parameters
-
Camera.Parameters 表示相机参数
-
它通过 Camera 实例对象的 getParameters 方法获取
-
通过它,开发者可以访问和修改相机的各种配置参数,例如,图片大小、预览大小、焦距、白平衡、曝光等
二、常用方法
1、previewSize 系列方法
(1)基本介绍
-
getPreviewSize()
:获取预览图像的大小 -
setPreviewSize(int width, int height)
:设置预览图像的大小 -
getSupportedPreviewSizes()
:获取预览大小支持的列表
(2)演示
Camera.Size previewSize = parameters.getPreviewSize();
Log.i(TAG, "============================== getPreviewSize");
Log.i(TAG, "---------- " + previewSize.width + " - " + previewSize.height);
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
Log.i(TAG, "============================== supportedPreviewSizes");
Log.i(TAG, "============================== supportedPreviewSizes size: " + supportedPreviewSizes.size());
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
Log.i(TAG, "---------- " + supportedPreviewSize.width + " - " + supportedPreviewSize.height);
}
- 输出结果
I/MyCameraTool: ============================== getPreviewSize
I/MyCameraTool: ---------- 2304 - 1728
I/MyCameraTool: ============================== supportedPreviewSizes
I/MyCameraTool: ============================== supportedPreviewSizes size: 42
I/MyCameraTool: ---------- 3200 - 1440
I/MyCameraTool: ---------- 3000 - 3000
I/MyCameraTool: ---------- 2560 - 1920
I/MyCameraTool: ---------- 2560 - 1440
I/MyCameraTool: ---------- 2560 - 1152
I/MyCameraTool: ---------- 2448 - 2448
I/MyCameraTool: ---------- 2400 - 1080
I/MyCameraTool: ---------- 2400 - 1028
I/MyCameraTool: ---------- 2304 - 1728
I/MyCameraTool: ---------- 2304 - 1296
I/MyCameraTool: ---------- 2280 - 1080
I/MyCameraTool: ---------- 2240 - 1008
I/MyCameraTool: ---------- 2160 - 1080
I/MyCameraTool: ---------- 1920 - 1440
I/MyCameraTool: ---------- 1920 - 1088
I/MyCameraTool: ---------- 1920 - 1080
I/MyCameraTool: ---------- 1744 - 1744
I/MyCameraTool: ---------- 1680 - 720
I/MyCameraTool: ---------- 1600 - 1200
I/MyCameraTool: ---------- 1600 - 720
I/MyCameraTool: ---------- 1560 - 720
I/MyCameraTool: ---------- 1560 - 702
I/MyCameraTool: ---------- 1440 - 1088
I/MyCameraTool: ---------- 1440 - 1080
I/MyCameraTool: ---------- 1280 - 960
I/MyCameraTool: ---------- 1280 - 768
I/MyCameraTool: ---------- 1280 - 720
I/MyCameraTool: ---------- 1088 - 1088
I/MyCameraTool: ---------- 1024 - 768
I/MyCameraTool: ---------- 960 - 720
I/MyCameraTool: ---------- 960 - 544
I/MyCameraTool: ---------- 960 - 540
I/MyCameraTool: ---------- 800 - 400
I/MyCameraTool: ---------- 720 - 480
I/MyCameraTool: ---------- 640 - 480
I/MyCameraTool: ---------- 640 - 360
I/MyCameraTool: ---------- 352 - 288
I/MyCameraTool: ---------- 320 - 240
I/MyCameraTool: ---------- 192 - 144
I/MyCameraTool: ---------- 192 - 108
I/MyCameraTool: ---------- 176 - 144
I/MyCameraTool: ---------- 160 - 96
2、pictureSize 系列方法
(1)基本介绍
-
getPictureSize()
:获取拍照时图片的大小 -
setPictureSize(int width, int height)
:设置拍照时图片的大小 -
getSupportedPictureSizes()
:获取拍照图片大小支持的列表
(2)演示
Camera.Size pictureSize = parameters.getPictureSize();
Log.i(TAG, "============================== getPictureSize");
Log.i(TAG, "---------- " + pictureSize.width + " - " + pictureSize.height);
List<Camera.Size> supportedPictureSizes = parameters.getSupportedPictureSizes();
Log.i(TAG, "============================== getSupportedPictureSizes");
Log.i(TAG, "============================== getSupportedPictureSizes: " + supportedPictureSizes.size());
for (Camera.Size supportedPictureSize : supportedPictureSizes) {
Log.i(TAG, "---------- " + supportedPictureSize.width + " - " + supportedPictureSize.height);
}
- 输出结果
I/MyCameraTool: ============================== getPictureSize
I/MyCameraTool: ---------- 4160 - 3120
I/MyCameraTool: ============================== getSupportedPictureSizes
I/MyCameraTool: ============================== getSupportedPictureSizes: 45
I/MyCameraTool: ---------- 4160 - 3120
I/MyCameraTool: ---------- 4160 - 2340
I/MyCameraTool: ---------- 4160 - 1872
I/MyCameraTool: ---------- 4000 - 3000
I/MyCameraTool: ---------- 4000 - 2250
I/MyCameraTool: ---------- 4000 - 1800
I/MyCameraTool: ---------- 3840 - 2160
I/MyCameraTool: ---------- 3264 - 2448
I/MyCameraTool: ---------- 3264 - 1840
I/MyCameraTool: ---------- 3264 - 1836
I/MyCameraTool: ---------- 3264 - 1472
I/MyCameraTool: ---------- 3200 - 1440
I/MyCameraTool: ---------- 3120 - 3120
I/MyCameraTool: ---------- 3000 - 3000
I/MyCameraTool: ---------- 2560 - 1920
I/MyCameraTool: ---------- 2560 - 1440
I/MyCameraTool: ---------- 2448 - 2448
I/MyCameraTool: ---------- 2400 - 1028
I/MyCameraTool: ---------- 2304 - 1728
I/MyCameraTool: ---------- 2304 - 1296
I/MyCameraTool: ---------- 2280 - 1080
I/MyCameraTool: ---------- 2240 - 1008
I/MyCameraTool: ---------- 2160 - 1080
I/MyCameraTool: ---------- 1920 - 1440
I/MyCameraTool: ---------- 1920 - 1088
I/MyCameraTool: ---------- 1920 - 1080
I/MyCameraTool: ---------- 1744 - 1744
I/MyCameraTool: ---------- 1600 - 1200
I/MyCameraTool: ---------- 1600 - 720
I/MyCameraTool: ---------- 1560 - 720
I/MyCameraTool: ---------- 1560 - 702
I/MyCameraTool: ---------- 1440 - 1088
I/MyCameraTool: ---------- 1440 - 1080
I/MyCameraTool: ---------- 1280 - 960
I/MyCameraTool: ---------- 1280 - 720
I/MyCameraTool: ---------- 1088 - 1088
I/MyCameraTool: ---------- 1024 - 768
I/MyCameraTool: ---------- 960 - 720
I/MyCameraTool: ---------- 960 - 544
I/MyCameraTool: ---------- 960 - 540
I/MyCameraTool: ---------- 800 - 400
I/MyCameraTool: ---------- 720 - 480
I/MyCameraTool: ---------- 640 - 480
I/MyCameraTool: ---------- 640 - 360
I/MyCameraTool: ---------- 320 - 240
3、setRotation 方法
(1)基本介绍
-
setRotation 方法用于设置相机拍照时照片的旋转角度
-
它可能会生效,也有部分情况会因为设备兼容性而无效
(2)setRotation 方法与 setDisplayOrientation 方法
-
setRotation 方法是 Camera.Parameters 实例对象的方法,setDisplayOrientation 方法是 Camera 实例对象的方法
-
setRotation 方法用于设置相机拍照时照片的旋转角度,setDisplayOrientation 方法用于设置相机预览图像的旋转角度
-
光是设置相机预览图像的旋转角度,不会影响相机拍照时照片的旋转角度
三、其他方法
1、focusMode 系列方法
(1)基本介绍
-
getFocusMode()
:获取当前的对焦模式 -
setFocusMode(String mode)
:设置相机的对焦模式
(2)演示
String focusMode = parameters.getFocusMode();
Log.i(TAG, "============================== getFocusMode");
Log.i(TAG,"---------- " + focusMode);
- 输出结果
I/MyCameraTool: ============================== getFocusMode
I/MyCameraTool: ---------- auto
2、whiteBalance 系列方法
(1)基本介绍
-
getWhiteBalance()
:获取当前的白平衡设置 -
setWhiteBalance(String value)
:设置相机的白平衡
(2)演示
String whiteBalance = parameters.getWhiteBalance();
Log.i(TAG, "============================== getWhiteBalance");
Log.i(TAG,"---------- " + whiteBalance);
- 输出结果
I/MyCameraTool: ============================== getWhiteBalance
I/MyCameraTool: ---------- auto
3、exposureCompensation 系列方法
(1)基本介绍
-
getExposureCompensation()
:获取当前的曝光补偿值 -
setExposureCompensation(int value)
:设置曝光补偿值
(2)演示
int exposureCompensation = parameters.getExposureCompensation();
Log.i(TAG, "============================== getExposureCompensation");
Log.i(TAG,"---------- " + exposureCompensation);
- 输出结果
I/MyCameraTool: ============================== getExposureCompensation
I/MyCameraTool: ---------- 0
4、flashMode 系列方法
(1)基本介绍
-
getFlashMode()
:获取当前的闪光灯模式 -
setFlashMode(String value)
:设置闪光灯模式
(2)演示
String flashMode = parameters.getFlashMode();
Log.i(TAG, "============================== getFlashMode");
Log.i(TAG,"---------- " + flashMode);
- 输出结果
I/MyCameraTool: ============================== getFlashMode
I/MyCameraTool: ---------- off