Search in sources :

Example 56 with Camera

use of android.hardware.Camera in project QRCode by 5peak2me.

the class CameraManager method requestPreviewFrame.

/**
	 * A single preview frame will be returned to the handler supplied. The data
	 * will arrive as byte[] in the message.obj field, with width and height
	 * encoded as message.arg1 and message.arg2, respectively.
	 * 
	 * @param handler
	 *            The handler to send the message to.
	 * @param message
	 *            The what field of the message to be sent.
	 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
Also used : Camera(android.hardware.Camera)

Example 57 with Camera

use of android.hardware.Camera in project QRCode by 5peak2me.

the class CameraManager method openDriver.

/**
	 * Opens the camera driver and initializes the hardware parameters.
	 * 
	 * @param holder
	 *            The surface object which the camera will draw preview frames
	 *            into.
	 * @throws IOException
	 *             Indicates the camera driver failed to open.
	 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
        if (requestedCameraId >= 0) {
            theCamera = OpenCameraInterface.open(requestedCameraId);
        } else {
            theCamera = OpenCameraInterface.open();
        }
        if (theCamera == null) {
            throw new IOException();
        }
        camera = theCamera;
    }
    theCamera.setPreviewDisplay(holder);
    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
    }
    Camera.Parameters parameters = theCamera.getParameters();
    // Save
    String parametersFlattened = parameters == null ? null : parameters.flatten();
    // temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = theCamera.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                theCamera.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }
}
Also used : Camera(android.hardware.Camera) IOException(java.io.IOException)

Example 58 with Camera

use of android.hardware.Camera in project QRCode by 5peak2me.

the class OpenCameraInterface method open.

/**
	 * Opens the requested camera with {@link Camera#open(int)}, if one exists.
	 * 
	 * @param cameraId
	 *            camera ID of the camera to use. A negative value means
	 *            "no preference"
	 * @return handle to {@link Camera} that was opened
	 */
public static Camera open(int cameraId) {
    int numCameras = Camera.getNumberOfCameras();
    if (numCameras == 0) {
        Log.w(TAG, "No cameras!");
        return null;
    }
    boolean explicitRequest = cameraId >= 0;
    if (!explicitRequest) {
        // Select a camera if no explicit camera requested
        int index = 0;
        while (index < numCameras) {
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
            Camera.getCameraInfo(index, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                break;
            }
            index++;
        }
        cameraId = index;
    }
    Camera camera;
    if (cameraId < numCameras) {
        Log.i(TAG, "Opening camera #" + cameraId);
        camera = Camera.open(cameraId);
    } else {
        if (explicitRequest) {
            Log.w(TAG, "Requested camera does not exist: " + cameraId);
            camera = null;
        } else {
            Log.i(TAG, "No camera facing back; returning camera #0");
            camera = Camera.open(0);
        }
    }
    return camera;
}
Also used : Camera(android.hardware.Camera)

Example 59 with Camera

use of android.hardware.Camera in project QRCode by 5peak2me.

the class OpenCameraInterface method open.

/**
	 * Opens a rear-facing camera with {@link Camera#open(int)}, if one exists,
	 * or opens camera 0.
	 */
public static Camera open() {
    int numCameras = Camera.getNumberOfCameras();
    if (numCameras == 0) {
        Log.w(TAG, "No cameras!");
        return null;
    }
    int index = 0;
    while (index < numCameras) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(index, cameraInfo);
        // CAMERA_FACING_BACK:手机背面的摄像头
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            break;
        }
        index++;
    }
    Camera camera;
    if (index < numCameras) {
        Log.i(TAG, "Opening camera #" + index);
        camera = Camera.open(index);
    } else {
        Log.i(TAG, "No camera facing back; returning camera #0");
        camera = Camera.open(0);
    }
    return camera;
}
Also used : Camera(android.hardware.Camera)

Example 60 with Camera

use of android.hardware.Camera in project android_frameworks_base by DirtyUnicorns.

the class ParameterUtils method convertSizeListToArray.

/**
     * Convert a camera API1 list of sizes into an array of sizes
     */
public static Size[] convertSizeListToArray(List<Camera.Size> sizeList) {
    checkNotNull(sizeList, "sizeList must not be null");
    Size[] array = new Size[sizeList.size()];
    int ctr = 0;
    for (Camera.Size s : sizeList) {
        array[ctr++] = new Size(s.width, s.height);
    }
    return array;
}
Also used : Size(android.util.Size) Camera(android.hardware.Camera) Point(android.graphics.Point)

Aggregations

Camera (android.hardware.Camera)164 Point (android.graphics.Point)28 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)25 Size (android.util.Size)25 Rect (android.graphics.Rect)19 IOException (java.io.IOException)19 Parameters (android.hardware.Camera.Parameters)18 ArrayList (java.util.ArrayList)17 Display (android.view.Display)16 WindowManager (android.view.WindowManager)16 CaptureRequest (android.hardware.camera2.CaptureRequest)15 SharedPreferences (android.content.SharedPreferences)10 Paint (android.graphics.Paint)10 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)10 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 SuppressLint (android.annotation.SuppressLint)8 Bitmap (android.graphics.Bitmap)8 MediaRecorder (android.media.MediaRecorder)7 R5Camera (com.red5pro.streaming.source.R5Camera)7 OpenCamera (com.google.zxing.client.android.camera.open.OpenCamera)6