Use this code

private void takePicture() {
        mCamera.takePicture(null, null, photoCallback);
    }

SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {


        public void surfaceCreated(SurfaceHolder holder)
        {
            mCamera=Camera.open();
            try
            {
                mCamera.setPreviewDisplay(previewHolder);
            }
            catch (Throwable t)
            {
                Log.e("PictureDemo-surfaceCallback","Exception
insetPreviewDisplay()", t);
                Toast.makeText(TakePic.this,t.getMessage(),
Toast.LENGTH_LONG).show();
            }
        }

        public void surfaceChanged(SurfaceHolder holder,int format, int
width, int height) {
            Camera.Parameters parameters=mCamera.getParameters();
            //Customise width/height here - otherwise defaults to screen
width/height
            parameters.setPreviewSize(width, height);
            parameters.setPictureFormat(PixelFormat.JPEG);
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            parameters.setJpegQuality(100);
            mCamera.setParameters(parameters);
            mCamera.startPreview();

        //-- Must add the following callback to allow the camera
toautofocus.
            mCamera.autoFocus(new Camera.AutoFocusCallback(){
                @Override
                public void onAutoFocus(boolean success, Camera camera) {
                    Log.d("HOME", "isAutofoucs " +
Boolean.toString(success));
                }
            } );
        }

        public void surfaceDestroyed(SurfaceHolder holder) {
            if(mCamera != null){
                mCamera.stopPreview();
                mCamera.release();
                mCamera=null;
            }
        }
    };

    Camera.PictureCallback photoCallback=new Camera.PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {

            FileOutputStream outStream = null;
            try {

                ImgName = String.format("%d.jpg",
System.currentTimeMillis());
                Log.d(TAG, "onPictureTaken - raw" + ImgName);
                Toast.makeText(TakePic.this, ImgName,
Toast.LENGTH_LONG).show();
                extStorageDirectory = TakePic.this.getFilesDir().toString();
                Toast.makeText(TakePic.this, extStorageDirectory,
Toast.LENGTH_LONG).show();
                Path = (extStorageDirectory + "/" +ImgName );
                Log.d(TAG, "onPictureTaken - raw" + Path);
                Toast.makeText(TakePic.this, Path,
Toast.LENGTH_LONG).show();
                outStream = new FileOutputStream(Path);
                outStream.write(data);
                outStream.close();
                Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
                GetLocationService();
                //startLocationUpdates();
                convertDateToString();
                SaveData("First Title", dateNow, "Shopping",
String.valueOf(lat),String.valueOf(lag), ImgName);


            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }
            Log.d(TAG, "onPictureTaken - jpeg");
            //-- This segment moved from surfaceDestroyed - otherwisethe
Camera is not properly released
            //finish();
        }
    };


On Fri, Feb 18, 2011 at 6:12 PM, Peter <[email protected]> wrote:

> Hello all,
> creating very basic camera code I got stuck at this: in followin code
> method onPictureTaken() is never being called:
>
>
>
> private PictureCallback pcb = new PictureCallback() {
>                        @Override
>                        public void onPictureTaken(byte[] data, Camera
> camera) {
>                                // Do something here - this place is never
> reached
>                        }
>            };
>
>
>
>                        Camera c = Camera.open();
>                        Parameters cp = c.getParameters();
>                        int JPEG = 0x100;
>                        cp.setPictureFormat(JPEG);
>                        c.setParameters(cp);
>                        c.takePicture(null, null, pcb);
>                        c.release();
>
>
>
>
> Have you met this behavior before? If so, how to overcome this?
> Behavior is consistent in emulator and in real hardware, versino is
> 2.1.
> Thanks for reading this.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 

Thanks and Regards,

Ankit Kasliwal
[email protected]
+91-9300-940-136

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to