capture image from custom camera android
<p>i have created one custom camera app camera is starting correctly i have one button on layout i want to capture the image whenever user click on button what is a code to save the preview image to sdcard...???</p>

<p>My Code Is....  </p>

<pre><code>@SuppressLint({ "SdCardPath", "NewApi" }) public class Camera_screen extends Activity {
            //AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);

        SurfaceHolder previewHolder=null;
        Camera mCamera=null;
        @Override
        public void onCreate(Bundle savedInstanceState) {


            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_camera);


            Button image=(Button)findViewById(R.id.button1);
            SurfaceView preview=(SurfaceView)findViewById(R.id.surfaceView1);


            previewHolder=preview.getHolder();
            previewHolder.addCallback(surfaceCallback);
            previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

           /* previewHolder.setFixedSize(getWindow().getWindowManager()
            .getDefaultDisplay().getWidth(), getWindow().getWindowManager()
            .getDefaultDisplay().getHeight());*/


            /*Button myButton = new Button(this);
            myButton.setText("Press Me");
    System.out.println("halyu");
            RelativeLayout layout = (RelativeLayout) findViewById(R.id.cam_out);
            layout.addView(myButton);*/
        }

            SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback(){
                public void surfaceCreated(SurfaceHolder holder) {
                    // The Surface has been created, acquire the camera and tell it where
                    // to draw.

                    try {

                         mCamera = Camera.open();
                       mCamera.setPreviewDisplay(holder);

                    } catch (IOException exception) {
                        mCamera.release();
                        mCamera = null;



                        // TODO: add more exception handling logic here
                    }
                }

                public void surfaceChanged(SurfaceHolder arg0, int arg1,int arg2, int arg3) {

                     Camera.Parameters parameters = mCamera.getParameters();
                     Camera.Size myBestSize = getBestPreviewSize(3, 4, parameters);
                  /* List&lt;Size&gt; sizes = parameters.getSupportedPreviewSizes();
                    Size   size = sizes.get(0);*/
                    if(myBestSize != null){
                     mCamera.setDisplayOrientation(90);
                        parameters.setPreviewSize(myBestSize.width, myBestSize.height);
                        mCamera.setParameters(parameters);
                        mCamera.startPreview();
                    }

                }

                public void surfaceDestroyed(SurfaceHolder arg0) {
                    // TODO Auto-generated method stub

                }
            };












        @SuppressLint("NewApi") public Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters){
            Camera.Size bestSize = null;
            List&lt;Camera.Size&gt; sizeList = parameters.getSupportedPreviewSizes();

            bestSize = sizeList.get(0);

            for(int i = 1; i &lt; sizeList.size(); i++){
             if((sizeList.get(i).width * sizeList.get(i).height) &gt;
               (bestSize.width * bestSize.height)){
              bestSize = sizeList.get(i);
             }
            }

            return bestSize;
           }



        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_camera, menu);
            return true;
        }





public void capture_btn(View view)
{


    \\ what to write here???????




}

    }
</code></pre>
