Matt
Matt

Reputation: 1757

Android Camera With Surface View Portrait

I have a App which uses the camera to take a picture. The camera has to have a overlay over the camera preview as the user will have to take the picture in a circle in the center of the screen so i have used surface view and placed a png image over the camera.

I am trying to get my surface view and the camera into portrait mode.

EDIT code updated but now getting error LOGTAG cannot be resolved..

public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub

    camera = Camera.open();
    try {
           Camera.Parameters parameters = camera.getParameters();
           if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "portrait");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(90);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(90);
           } else {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "landscape");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(0);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(0);
           }
          camera.setParameters(parameters);
          camera.setPreviewDisplay(holder);
      } catch (IOException exception) {
         camera.release();
        Log.v(LOGTAG,exception.getMessage());
       }
        camera.startPreview();
    }


public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera.stopPreview();
    camera.release();
    camera = null;
    previewing = false;
}
}

Upvotes: 1

Views: 1771

Answers (1)

Sujit
Sujit

Reputation: 10632

use this code...this will solve your problem..

 public void surfaceCreated(SurfaceHolder holder) {
      camera = Camera.open();
      try {
           Camera.Parameters parameters = camera.getParameters();
           if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "portrait");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(90);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(90);
           } else {
              // This is an undocumented although widely known feature
              parameters.set("orientation", "landscape");
              // For Android 2.2 and above
              //camera.setDisplayOrientation(0);
              // Uncomment for Android 2.0 and above
              //parameters.setRotation(0);
           }
          camera.setParameters(parameters);
          camera.setPreviewDisplay(holder);
      } catch (IOException exception) {
         camera.release();
        Log.v(LOGTAG,exception.getMessage());
       }
        camera.startPreview();
    }

Upvotes: 2

Related Questions