5

On all the handsets I've tried, including the Galaxy Nexus with both API 2.3.7 and 4.0 after the takePicture method is called the surface view changes to the image that was taken, the "Image Review".

I've tested on these tablet devices and the image review didn't show up: XOOM API 3.1 Galaxy Tab 10.1 API 3.1 Galaxy Tab 10.1 API 3.2

surfaceView = (SurfaceView)findViewById(R.id.surfaceView);

surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

...

    public void takePicture() {
        cam.takePicture(this, null, this); //Shuttercallback, RawCallback, JpegCallback
    }

...

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {       
    // Stop preview before changing camera parameters
    if(isPreviewRunning) {
        this.cam.stopPreview();
    }

    Camera.Parameters p = this.cam.getParameters();
    LogUtils.info("CheckCapture", "Preview Size: " + String.valueOf(width) +"x" + String.valueOf(height));
    p.setPreviewSize(width, height);

    //Set picture size to a multiple of previewSize to maintain aspect ratio AND minimum capture width
    //LogUtils.info("CheckCapture", "Picture Size: " + String.valueOf(width*factor) +"x" + String.valueOf(height*factor));
    p.setPictureSize(width, height);
    p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

    //Set picture format (we can check device capabilities, but all devices at API level 8 should support JPEG)
    p.setPictureFormat(PixelFormat.JPEG);

    //Set new camera parameters
    try {
        this.cam.setParameters(p);
    }catch (Exception e) {
        e.printStackTrace();
    }

    //Setup preview display on our surfaceViewHolder
    try {
        this.cam.setPreviewDisplay(surfaceHolder);
    } catch (IOException e) {
        e.printStackTrace();
    }

    //Start preview
    this.cam.startPreview();
    this.isPreviewRunning = true;
}
Erik B
  • 2,810
  • 1
  • 34
  • 38
  • It seems like a problem I have [here](http://stackoverflow.com/questions/11676726/its-a-kind-of-magic-videoview-and-displaying-videos-on-android-3-1-vs-4-1) but with videos and with the same devices. Did you fix it? – 2dvisio Jul 26 '12 at 22:11
  • Unfortunately I gave up and took an approach similar to dinesh's. Get the image from the capture and show it in an ImageView like so, `imageView.setImageBitmap(ImageUtils.jpegDecode(data));` – Erik B Sep 13 '12 at 18:20

1 Answers1

3

on btn_click.onclickListener use callback method as follow

_btn_click.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            ShutterCallback shutterCallBack = new ShutterCallback() {
                @Override
                public void onShutter() {}
            };

            PictureCallback pictureCallBack = new PictureCallback() {
                @Override
                public void onPictureTaken(byte[] data, Camera camera) {}
            };

            PictureCallback pictureCallBackJPG = new PictureCallback() {
                @Override
                public void onPictureTaken(byte[] data, Camera camera) {

                    Bitmap capturedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

                }
            };
            setFlashMode();
            camera.takePicture(shutterCallBack, pictureCallBack,
                    pictureCallBackJPG);
            showProgressDialog("Bitte warten", CameraCaptureActivity.this);
        }
    });

in this code main line is

Bitmap capturedBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

use capturedBitmap in imageview.setImageBitmap(capturedBitmap); to show the image.

Happy Coding

dinesh sharma
  • 3,312
  • 1
  • 22
  • 32