gpt4 book ai didi

java - Camera.Parameters 设备特定崩溃(Samsung S3 Mini)

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:05 25 4
gpt4 key购买 nike

以下代码适用于 Galaxy Nexus、Samsung S3 和 HTC One X,但在 Samsung S3 Mini 上会崩溃

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "entering surfaceChanged");
Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();

// set barcode scene mode
if (parameters.getSupportedSceneModes() != null && parameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_BARCODE)){
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE);
Log.d(TAG, "setting parameters.setSceneMode(Camera.Parameters.SCENE_MODE_BARCODE)");
}


Camera.Size size = previewSizes.get(0);
if (previewSizes.size() > 2)
size = previewSizes.get(2);
else if (previewSizes.size() > 1)
size = previewSizes.get(1);

parameters.setPreviewSize(size.width, size.height);
Log.d(TAG, "picsize w: " + Integer.toString(size.width) + " h: " + Integer.toString(size.height));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
Log.d(TAG, "setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)");
} else {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
Log.d(TAG, "setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)");
}

// setup cam flash mode
if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FLASH_MODE_AUTO)){
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
Log.d(TAG, "setting .setFlashMode(Camera.Parameters.FLASH_MODE_AUTO)");
}

int maxZoom = parameters.getMaxZoom();
int zoom = (int) Math.floor(maxZoom / 3);
if (parameters.isZoomSupported()) {
if (zoom >= 0 && zoom < maxZoom) {
parameters.setZoom(zoom);
Log.d(TAG, "setting .setZoom(" + Integer.toString(zoom) +")");
} else {
// zoom parameter is incorrect
Log.d(TAG, "setting no zoom");
}
}
camera.setParameters(parameters);
camera.startPreview();
}

日志输出:

8   05-13 10:54:45.864 D/CameraSurfaceView(11784): entering surfaceChanged
9 05-13 10:54:45.874 D/CameraSurfaceView(11784): picsize w: 800 h: 480
10 05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)
11 05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setFlashMode(Camera.Parameters.FLASH_MODE_AUTO)
12 05-13 10:54:45.874 D/CameraSurfaceView(11784): setting .setZoom(10)
13 05-13 10:54:45.914 D/AndroidRuntime(11784): Shutting down VM
14 05-13 10:54:45.914 W/dalvikvm(11784): threadid=1: thread exiting with uncaught exception (group=0x411422a0)

堆栈跟踪:

java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1452)
at com.getznap.znap.CameraSurfaceView.surfaceChanged(CameraSurfaceView.java:103)
at android.view.SurfaceView.updateWindow(SurfaceView.java:602)
at android.view.SurfaceView.access$000(SurfaceView.java:81)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:173)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1944)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)

我猜 S3 mini 的某个相机参数有问题。我没有 S3 Mini,所以无法一一测试所有参数。我的代码有没有明显的错误?

最佳答案

发生在

parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);

三星不支持这个你可以试试

parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

关于java - Camera.Parameters 设备特定崩溃(Samsung S3 Mini),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16519048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com