-1

I'm trying to learn an Augmented Reality basic from this article : http://www.devx.com/wireless/Article/42482/0/page/2

when it run, the camera took an opposite orientation. My question is how to get a fixed and normal view with the camera. This is the CustomCameraView Class:

package com.syariati.camera;

import android.content.Context;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CustomCameraView extends SurfaceView {
    Camera camera;
    SurfaceHolder surfaceHolder;

    public CustomCameraView(Context context){
        super(context);
        surfaceHolder = this.getHolder();
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        surfaceHolder.addCallback(surfaceHolderListener);
    }

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

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            camera.stopPreview();
            camera.release();
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            camera = Camera.open();
            try{
                camera.setPreviewDisplay(surfaceHolder);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width,
                int height) {
            // TODO Auto-generated method stub
            Parameters params = camera.getParameters();
            params.setPictureFormat(PixelFormat.JPEG);
            camera.setParameters(params);
            camera.startPreview();
        }
    };
}

Should I add another method on params ??

Sorry for my bad English. Thank you.

This is how the problem is solved.

add :

camera.setDisplayOrientation(90);

Android - Camera preview is sideways

Community
  • 1
  • 1
farissyariati
  • 365
  • 4
  • 9
  • 21

2 Answers2

2

Set orientation Degree as per your requirment because I had user 90 for front camera and 270 degree for back camera:

Camera.Parameters params = camera.getParameters();
params.set("rotation", 90);
camera.setParameters(params);
uelordi
  • 2,189
  • 3
  • 21
  • 36
0

Goto your application AndroidManifest.xml file and then follow

Application tab -> select CustomCameraView activity -> 
attributes for CustomCameraView activity -> screen orientation -> select portrait.

And run it- Njoy...

Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
  • it didn't work when I add portrait. However, landscape working fine, but with the change of the screen orientation off course. – farissyariati Mar 25 '12 at 14:03