gpt4 book ai didi

android - 将缩放功能添加到相机崩溃并出现致命异常

转载 作者:行者123 更新时间:2023-11-30 04:23:58 25 4
gpt4 key购买 nike

您好,我正在尝试使用 SurfaceView 和 Camera 类制作相机。这里一切正常,除了缩放功能。当我在开始使用 MediaRecorder 录制之前单击缩放时,它可以正常工作,但如果我开始录制并单击缩放,它就会崩溃。这是我的代码。如何为我的相机添加变焦功能。任何帮助深表感谢。谢谢。

这是我的 smoothZoom 代码,

 zoomControls.setOnZoomInClickListener(new OnClickListener() {

public void onClick(View v) {

try
{
currentZoomLevel++;
myCamera.startSmoothZoom(currentZoomLevel);


}catch(IllegalArgumentException e)
{
currentZoomLevel--;
zoomControls.setIsZoomInEnabled(false);
}
}
});


Parameters parameters = myCamera.getParameters();
parameters.setFlashMode(getFlashModeSetting());
myCamera.setParameters(parameters);

mediaRecorder = new MediaRecorder();
myCamera.unlock();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());

这是我的逻辑,

08-21 14:05:36.171: ERROR/AndroidRuntime(6426): FATAL EXCEPTION: main
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): java.lang.RuntimeException: start smooth zoom failed
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.hardware.Camera.startSmoothZoom(Native Method)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at com.camvideocorder.CamVideoCorderActivity$2.onClick(CamVideoCorderActivity.java:95)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.view.View.performClick(View.java:2485)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.view.View$PerformClick.run(View.java:9089)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.os.Handler.handleCallback(Handler.java:587)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.os.Handler.dispatchMessage(Handler.java:92)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.os.Looper.loop(Looper.java:123)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at android.app.ActivityThread.main(ActivityThread.java:3806)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at java.lang.reflect.Method.invoke(Method.java:507)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-21 14:05:36.171: ERROR/AndroidRuntime(6426): at dalvik.system.NativeStart.main(Native Method)

最佳答案

你能具体说明你使用的是哪个版本的安卓吗?录制视频时缩放功能仅在android 4.0中添加。

关于android - 将缩放功能添加到相机崩溃并出现致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8833979/

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