我得到了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中失效,谁可以告诉我如何解决它,请帮助我,谢谢
答案 0 :(得分:2)
在尝试拨打startPreview()
之前,您需要拨打takePicture()
。拨打Camera.open()
后,请执行此操作。
重要提示:致电
startPreview()
开始更新预览表面。 必须先开始预览才能拍照。