2

In my android app i m using the camera and starting it programmatically .I run my code on samsung gt-s5360 ,but the view is rotated by 90 degree anti clock wise.my code works fine on HTC wildfire-s.On this device the camera view is showing correctly without rotating the view .But it is not showing the correct view on each device.So how can i write the code that works for all devices(android) .My android jar is 2.2 and API level is 8.Please help me .Here is my code.

public class AndroidCamera extends Activity implements SurfaceHolder.Callback{
    int rotate=90;
    Camera camera;
    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean previewing = false;
    LayoutInflater controlInflater = null;
    public static ArrayList<Activity> activities=new ArrayList<Activity>();
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        activities.add(this);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


        Intent i=new Intent();
        i.setClassName("a.b.c","a.b.c.DialPad");
        startActivity(i);

    }


    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub
        //this.camera.setDisplayOrientation(90);
        if(previewing){
            camera.stopPreview();
            previewing = false;
        }

        if (camera != null){
            try {
                camera.setPreviewDisplay(surfaceHolder);
                camera.startPreview();
                //camera.setDisplayOrientation(90);
                previewing = true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        camera = Camera.open();
        camera.setDisplayOrientation(rotate);
        //Parameters p= camera.getParameters();
        //p.setRotation(90);
        /*if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            p.set("orientation", "portrait");
            p.set("rotation",90);
            Toast.makeText(getApplicationContext(), "Potrait Mode", Toast.LENGTH_SHORT).show();
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {                               
            p.set("orientation", "landscape");          
            p.set("rotation", 90);
            Toast.makeText(getApplicationContext(), "Landscape Mode", Toast.LENGTH_SHORT).show();
        }*/




    }

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

    }
picaso
  • 713
  • 2
  • 14
  • 26
  • does this help? http://stackoverflow.com/questions/5309029/android-camera-rotate – John Boker Dec 12 '11 at 13:39
  • i have tried that code but does not forks for me. Please help – picaso Dec 13 '11 at 05:28
  • It seems some devices just don't support setDisplayOrientation. I'm facing same issue on my Galaxy Y. Did you find out something? I'd like to know at least if setDisplayOrientation succeeded, to lock it to landscape if it didn't. http://stackoverflow.com/questions/10385147/android-camera-preview-rotation – Jorge Cevallos Aug 31 '12 at 17:04

0 Answers0