title: Custom Camera display orientation in android
body: <p>How to maintain camera display orientation in android when i create custom camera class.
  when i not perfect solution for more then android device then what i do for this scenarios and when some device do on camera landscape or some device do on camera portrait.</p>
  
  <pre><code> public CameraSurface(Context context) {
          super(context);
  
          try {
              holder = this.getHolder();
              holder.addCallback(this);
              holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          try {
              // Open the Camera in preview mode
              this.camera = Camera.open();
              this.camera.setPreviewDisplay(holder);
          } catch (IOException ioe) {
              ioe.printStackTrace(System.out);
          }
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          // Surface will be destroyed when replaced with a new screen
          // Always make sure to release the Camera instance
          camera.stopPreview();
          camera.release();
          camera = null;
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) {
          // Now that the size is known, set up the camera parameters and begin
          // the preview.
  //      Camera.Parameters parameters = camera.getParameters();
  //      System.out.println("height...."+width+" height....."+height);
  //      parameters.setPreviewSize(width, height);
  //      camera.setParameters(parameters);
  //      camera.startPreview();
          Camera.Parameters parameters = camera.getParameters();
          List&lt;Camera.Size&gt; previewSizes = parameters.getSupportedPreviewSizes();
  
          // You need to choose the most appropriate previewSize for your app
          Camera.Size previewSize;
          if(previewSizes.size() &gt; 1){
              previewSize =previewSizes.get(1);  // .... select one of previewSizes here
          }else{
              previewSize =previewSizes.get(0);
          }
          parameters.setPreviewSize(previewSize.width, previewSize.height);
          camera.setParameters(parameters);
          camera.setDisplayOrientation(90);
          camera.startPreview();
      }
  </code></pre>