title: How can i capture image with a touch on surface view
body: <pre><code>public class AndroidCamera extends Activity implements OnTouchListener, SurfaceHolder.Callback{
  
  Camera camera;
  SurfaceView surfaceView;
  SurfaceHolder surfaceHolder;
  boolean previewing = false;;
  PictureCallback rawCallback;
  ShutterCallback shutterCallback;
  PictureCallback jpegCallback;
  
  
  
  EditText txtData, Info,Age;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
     Button buttonStartCameraPreview = (Button)findViewById(R.id.startcamerapreview);
     Button buttonStopCameraPreview = (Button)findViewById(R.id.stopcamerapreview);
     Button buttonCapturePreview = (Button) findViewById(R.id.capturepreview);
  
  
  
      txtData = (EditText) findViewById(R.id.editText1);
     Info = (EditText) findViewById(R.id.Name);
      Info.setHint("enter  name");
      Age = (EditText) findViewById(R.id.Age);
      Age.setHint("Age");
  
  
  
      getWindow().setFormat(PixelFormat.UNKNOWN);
      surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
      surfaceHolder = surfaceView.getHolder();
      surfaceHolder.addCallback(this);
  
  
  
  
      rawCallback = new PictureCallback() 
      {
          public void onPictureTaken(byte[] data, Camera camera)
          {
              Log.d("Log", "onPictureTaken - raw");
          }
      };
  
      shutterCallback = new ShutterCallback()
      {
          public void onShutter() {
              Log.i("Log", "onShutter'd");
          }
      };
  
    //  onTouchEvent(null);
  
      jpegCallback = new PictureCallback()
      {
          public void onPictureTaken(byte[] data, Camera camera) 
           {
  
              Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
              File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Asw");
              imagesFolder.mkdirs(); 
              Date d = new Date();
              CharSequence s  = DateFormat.format("MM-dd-yy hh-mm-ss", d.getTime());
              File output = new File(imagesFolder, s.toString() + ".jpg");
  
              Uri uriSavedImage = Uri.fromFile(output);
              imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
              OutputStream imageFileOS;
  
              try {
                  imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
                  imageFileOS.write(data);
                  imageFileOS.flush();
                  imageFileOS.close();
  
                  Toast.makeText(AndroidCamera.this, 
                          "Image saved: ", 
                          Toast.LENGTH_LONG).show();
  
                  } 
              catch (FileNotFoundException e) 
                  {
                  e.printStackTrace();
                  } 
              catch (IOException e)
              {
                  e.printStackTrace();
              } 
              finally
              {}
              Log.d("Log", "onPictureTaken - jpeg");
          }
      };
  
      buttonStartCameraPreview.setOnClickListener(new Button.OnClickListener()
      {
  
          @TargetApi(Build.VERSION_CODES.GINGERBREAD)
          @Override
          public void onClick(View v) 
          {
              if(!previewing)
              {
                  camera = Camera.open(0);
                  if (camera != null)
                  {
  
                      try {
  
                          camera.setPreviewDisplay(surfaceHolder);
                          camera.startPreview();
                          previewing = true;
                          } 
                      catch (IOException e) 
                          {
  
                          e.printStackTrace();
                          }
                  }else txtData.setText("null");
              }
          }});
  
  
  
      buttonCapturePreview.setOnClickListener(new OnClickListener()
     {
  
          @Override
          public void onClick(View v) 
          {
  
              captureImage();
          }
  
          private void captureImage() 
          {
              camera.takePicture(shutterCallback, rawCallback, jpegCallback);
  
          }
      });
      buttonStopCameraPreview.setOnClickListener(new Button.OnClickListener(){
  
          @Override
          public void onClick(View v) 
          {
  
              if(camera != null &amp;&amp; previewing)
              {
                  camera.stopPreview();
                  camera.release();
                  camera = null;
  
                  previewing = false;
              }
          }});
  
  
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.android_camera, menu);
      return true;
  }
  
  
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width,
          int height) 
  {
      // TODO Auto-generated method stub
  
  }
  
  
  @Override
  public void surfaceCreated(SurfaceHolder holder) 
  {
      // TODO Auto-generated method stub
  
  }
  
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder)
  {
      // TODO Auto-generated method stub
  
  }
  
  
  
  
  public boolean onTouch(View v, MotionEvent event)
  {
  
      if (event.getAction() == MotionEvent.ACTION_MOVE)
      {
      camera.takePicture(shutterCallback, rawCallback, jpegCallback);
  
      }
      return super.onTouchEvent(event);
  
      //return false;
  }
  </code></pre>
  
  <p>I have used a button to capture the image. Now i wanted to capture and save the image with just a touch on surface view. I wrote some code.Its not showing any error but it is not working also. Could you please tell me where i am going wrong. Please help</p>