Take and save picture on button press

后端 未结 2 880
死守一世寂寞
死守一世寂寞 2021-01-30 19:15

I\'m creating an Android application which uses user captured images as part of a larger process. So far my XML layout has a SurfaceView and Button inside a RelativeLayout. I\'v

相关标签:
2条回答
  • 2021-01-30 19:23

    I think CommonsWare has really already answered most of this question, but this might work for the auto focus and the shutter sound. This is a guess, since I'm not at a machine where I can compile/test any of this.

    In your button-press-handling code, I believe you should call (possibly by message passing)

    camera.autoFocus(new Camera.AutoFocusCallback() {
      Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() {
        public void onShutter() {
          // Play your sound here.
        }
      };
      public void onAutoFocus(boolean success, Camera camera) {
        camera.takePicture(shutterCallback, null, photoCallback);
      }
    });  
    

    where camera is your camera object, and photoCallback is the same as in CommonsWare's example.

    Exactly what is it that you are stuck on?

    Oh, and don't forget to add the <uses-feature> tag android.hardware.camera.autofocus. :)

    0 讨论(0)
  • 2021-01-30 19:33

    Here is a sample application that handles the take-a-picture-and-save-it part. Auto-focus, clicky, Toast, and saving to the app-local file store vs. the SD card are left as exercises for the student. :-)

    0 讨论(0)
提交回复
热议问题