1

我得到了 LogCat:

 java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1061)
at android.hardware.Camera.takePicture(Camera.java:1006)
at com.cidtech.portraitcatch.service.MyService.takePic(MyService.java:168)
at com.cidtech.portraitcatch.service.MyService$1.onClick(MyService.java:78)
at android.view.View.performClick(View.java:4088)
at android.view.View$PerformClick.run(View.java:16984)
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:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

居里代码如下:

public void takePic(){
    home_takePic.setEnabled(false);
    camera = Camera.open();
    if(bitmapList == null){
        bitmapList = new ArrayList<Bitmap>();
    }
    for(int i=0; i<5; i++){

        camera.takePicture(null, null, new MyPictureCallback());
        SystemClock.sleep(1000);
    }

            saveBitmapToSdcard();

    releaseResource();
    home_takePic.setEnabled(true);
}

我也这样做:

public void takePic(){
    home_takePic.setEnabled(false);
    camera = Camera.open();
    ***camera.startPreview();***
    if(bitmapList == null){
        bitmapList = new ArrayList<Bitmap>();
    }
    for(int i=0; i<5; i++){

        camera.takePicture(null, null, new MyPictureCallback());
        SystemClock.sleep(1000);
    }

    //      saveBitmapToSdcard();

    releaseResource();
    home_takePic.setEnabled(true);
}

但仍然得到相同的异常

方法camera.takePicture在4.0.4版本执行过,在4.1.1版本失败,谁能告诉我怎么解决,请帮帮我,谢谢

4

1 回答 1

2

startPreview()在尝试调用 之前,您需要先调用takePicture()。打电话后执行此操作Camera.open()

根据 Android 文档

重要提示:调用startPreview()以开始更新预览图面。 必须先开始预览,然后才能拍照。

开始预览文档

于 2013-10-10T04:42:53.093 回答