0
        } 
 
        // stop preview before making changes 
        try { 
            camera.stopPreview();
        } catch (Exception e){
            // ignore: tried to stop a non-existent preview 
        } 
 
        // set preview size and make any resize, rotate or 
        // reformatting changes here 
        Camera.Parameters parameters = camera.getParameters();
        Display display = ((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        switch(display.getRotation()){
            case Surface.ROTATION_0:
                camera.setDisplayOrientation(90);
                break; 
            case Surface.ROTATION_270:
                camera.setDisplayOrientation(180);
                break; 
            case Surface.ROTATION_90:
            case Surface.ROTATION_180:
        } 
 
 
        if (previewCallback != null) {
            camera.setPreviewCallbackWithBuffer(previewCallback);
            Camera.Size size = parameters.getPreviewSize();
            byte[] data = new byte[size.width*size.height*
                    ImageFormat.getBitsPerPixel(parameters.getPreviewFormat())/8];
            camera.addCallbackBuffer(data);
        } 
        camera.setParameters(parameters);
 
        // start preview with new settings 
        try { 
            camera.setPreviewDisplay(this.holder);
            camera.startPreview();
 
        } catch (Exception e){
            Log.d(TAG, "Error starting camera preview: " + e.getMessage());
        } 
    }