开发者

problem with taking pictures using the android camera

I have an app where I'm using the android camera to take pictures.I have built my own android camera.And pictures are taken by pressing a button.

Something like this:

  public void onClick(View arg0) {
  mCamera.takePicture(null, mPictureCallback, mPictureCallback);
  }


Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] imageData, Camera c) {

        if (imageData != null) {
            Intent mIntent = new Intent();


            Bundle b = new Bundle();
            b.putByteArray("imageData", imageData);
            Intent i = new Intent(mContext, ViewPhoto.class);
            i.putExtras(b);
            startActivity(i);

            setResult(FOTO_MODE, mIntent);
            finish();

        }
    }
};

Once the picture is taken I us开发者_StackOverflowe an intent and send the bytes to another activity.

The big problem is that if I take several photos, one by one by pressing the button, my app crashes at this line:

mCamera.takePicture(null, mPictureCallback, mPictureCallback);

This is how my logcat looks like:

java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:746)
at android.hardware.Camera.takePicture(Camera.java:710)
at com.Xperiaproject.TakePhoto.onClick(TakePhoto.java:216)
at android.view.View.performClick(View.java:2534)
at android.view.View$PerformClick.run(View.java:9210)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)

Any idea how to solve this?

EDIT: I've also tried:

mCamera.takePicture(null, null, mPictureCallback);

but crashes after several pictures!!!

!!!!!!!!This is my whole code: http://pastebin.com/0U1pQSak


Make sure that you call Camera.startPreview() again after you have taken a picture.

8) After taking a picture, preview display will have stopped. To take more photos, call startPreview() again first.

from the Camera class documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜