Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

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 use 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...