takePicture在棒棒糖中失败了

时间:2015-05-19 12:33:08

标签: android service camera

以下代码在后台拍照。它适用于棒棒糖下面的所有版本,但在takePicture(null,null,mcall)中提供了运行时异常。任何想法..?

   public void takePictures(final int delay) 
{
      final Camera.PictureCallback mCall = new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                Log.e(TAG, "Picture taken, saving....");
                Uri uriTarget = getContentResolver().insert//(Media.EXTERNAL_CONTENT_URI, image);
                        (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
                OutputStream imageFileOS;
                try {
                    imageFileOS = getContentResolver().openOutputStream(uriTarget);
                    imageFileOS.write(data);
                    imageFileOS.flush();
                    imageFileOS.close();
                    Log.e("Image saved: ", uriTarget.toString());
                    savePictures(getRealPathFromURI(uriTarget.toString()));
                    mCamera.stopPreview();
                    mCamera.release();
                    mCamera = null;

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                    Log.e("Image not  saved: ", e.toString());
                } catch (IOException e) {
                    Log.e("Image not  saved:2 ", e.toString());
                    e.printStackTrace();
                }

            }
        };
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
           thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int numOfPicturesAlreadyTaken = 0; numOfPicturesAlreadyTaken < numOfPictures; numOfPicturesAlreadyTaken++) {

                            Log.e(TAG, "Opening camera");
                            mCamera = Camera.open();
                            //mCamera.setPreviewDisplay(sv.getHolder());
                            parameters = mCamera.getParameters();
                            parameters.setRotation(90);
                            mCamera.setParameters(parameters);
                            mCamera.startPreview();

                            mCamera.takePicture(null, null, mCall);


                            Thread.sleep(delay);




                    }
                }
            });
            thread.start();
        } else {
            Toast.makeText(this, "No camera found.", Toast.LENGTH_SHORT).show();
        }
    }

错误 只进入棒棒糖 代码在服务中拍摄背景图片。

java.lang.RuntimeException: takePicture failed
            at android.hardware.Camera.native_takePicture(Native Method)
            at android.hardware.Camera.takePicture(Camera.java:1436)
            at android.hardware.Camera.takePicture(Camera.java:1381)
            at com.codebrew.lockdown.services.CameraService$2.run(CameraService.java:133)
            at java.lang.Thread.run(Thread.java:818)

0 个答案:

没有答案