Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.hardware.Camera;
import android.util.Log;

public class Main {
    public static final String TAG = "CameraUtils";

    /**
     * Return camera instance
     */
    public static Camera getCameraInstance(int displayOrientation) {
        Camera cam = null;
        try {
            cam = Camera.open();

            // More efficient way to find available cameras. Nexus 7 needs this.
            if (cam == null) {
                int availableCameras = Camera.getNumberOfCameras();
                for (int i = 0; i < availableCameras; i++) {
                    cam = Camera.open(i);
                    if (cam != null)
                        break;
                }
            }

            cam.setDisplayOrientation(displayOrientation);
            Log.d(TAG, "Getting Camera: " + cam.toString());
        } catch (Exception e) {
            Log.e(TAG, "Camera is not available (in use or does not exist)");
            Log.e(TAG, e.toString());
        }
        return cam;
    }
}