LOG显示为:
09-01 18:47:17.348 15656 15675 E AndroidRuntime: FATAL EXCEPTION: Camera Handler Thread
09-01 18:47:17.348 15656 15675 E AndroidRuntime: Process: com.android.camera, PID: 15656
09-01 18:47:17.348 15656 15675 E AndroidRuntime: java.lang.RuntimeException: setParameters failed
09-01 18:47:17.348 15656 15675 E AndroidRuntime: at android.hardware.Camera.native_setParameters(Native Method)
这种情况下都是参数设置错误。
主要常见错误在以下两个方法的参数设置
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPictureSize(1600, 1200);
parameters.setPreviewSize(w, h);
该怎样去设置好这两个参数设置呢?
首先我们将数据获取处理看看这两个方法能够传递那些参数进来。
List<Size> pictureSizes = parameters.getSupportedPictureSizes();
int length = pictureSizes.size();
for (int i = 0; i < length; i++) {
Log.e("TAG","SupportedPictureSizes : " + pictureSizes.get(i).width + "x" + pictureSizes.get(i).height);
}
List<Size> previewSizes = parameters.getSupportedPreviewSizes();
length = previewSizes.size();
for (int i = 0; i < length; i++) {
Log.e("TAG","SupportedPreviewSizes : " + previewSizes.get(i).width + "x" + previewSizes.get(i).height);
}
通过日志我们可以看到
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 640x480
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 1600x1200
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 2048x1536
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 2592x1456
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 2592x1952
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 3264x1840
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 3264x2448
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 4160x2336
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 4160x3120
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPictureSizes : 3104x3104
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 176x144
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 240x160
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 352x288
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 320x240
05-21 17:43:17.545: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 480x320
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 640x480
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 720x544
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 960x544
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 960x720
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 720x720
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 1280x720
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 1440x1080
05-21 17:43:17.550: E/FFFFFFFFFFFFFFFFFFFFF(21262): SupportedPreviewSizes : 1920x1080
05-21 17:43:17.550: E/==============(21262): ==w=1920========h=1080 隐藏返回键我手机对应的分辨率
所以这两个方法里面的参数必须是上面可以对应上的。
05-21 17:47:43.575: E/==============(21262): ==w=1794========h=1080 显示返回键的分辨率
我的问题是使用荣耀6手机返回键和home都是在屏幕内导致高的分辨率达不到1920*1080。而实际只有1794*1080而导致错误。