Najib Puthawala Najib Puthawala - 1 year ago 79
Android Question

Custom Camera display orientation in android

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.

public CameraSurface(Context context) {

try {
holder = this.getHolder();

} catch (Exception ex) {

public void surfaceCreated(SurfaceHolder holder) {
try {
// Open the Camera in preview mode =;;
} catch (IOException ioe) {

public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when replaced with a new screen
// Always make sure to release the Camera instance
camera = null;

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<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();

// You need to choose the most appropriate previewSize for your app
Camera.Size previewSize;
if(previewSizes.size() > 1){
previewSize =previewSizes.get(1); // .... select one of previewSizes here
previewSize =previewSizes.get(0);
parameters.setPreviewSize(previewSize.width, previewSize.height);

Answer Source

Following two links will help you:

Using Camera API.
Android Camera Preview is sideways.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download