Search in sources :

Example 71 with Camera

use of android.hardware.Camera in project BarcodeEye by BarcodeEye.

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 72 with Camera

use of android.hardware.Camera in project BarcodeEye by BarcodeEye.

the class OpenCameraInterface method open.

/**
     * Opens a rear-facing camera with {@link Camera#open(int)}, if one exists,
     * or opens camera 0.
     * @throws InterruptedException
     */
public static Camera open() throws InterruptedException {
    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);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            break;
        }
        index++;
    }
    Camera camera = null;
    long timeout = System.currentTimeMillis() + MAX_WAIT_TIME;
    int attempt = 0;
    while (camera == null && System.currentTimeMillis() < timeout) {
        attempt++;
        Log.v(TAG, "Sleeping 100ms - attempt " + attempt);
        Thread.sleep(100);
        try {
            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);
            }
        } catch (RuntimeException e) {
            Log.w(TAG, "RuntimeException: " + e.getMessage());
        }
    }
    return camera;
}
Also used : Camera(android.hardware.Camera)

Example 73 with Camera

use of android.hardware.Camera in project wechat by motianhuo.

the class CameraConfigurationManager method initFromCameraParameters.

/**
	 * Reads, one time, values from the camera that are needed by the app.
	 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");
    Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenResolution = new Point(display.getWidth(), display.getHeight());
    Log.d(TAG, "Screen resolution: " + screenResolution);
    /** modify here **/
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;
    // preview size is always something like 480*320, other 320*480
    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }
    /** end **/
    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
    Log.d(TAG, "Camera resolution: " + screenResolutionForCamera);
/*
		 * cameraResolution = getCameraResolution(parameters, screenResolution);
		 * Log.d(TAG, "Camera resolution: " + screenResolution);
		 */
/** end **/
}
Also used : Camera(android.hardware.Camera) Point(android.graphics.Point) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 74 with Camera

use of android.hardware.Camera in project CameraView by CJT2325.

the class CameraInterface method handleFocus.

public void handleFocus(final Context context, final float x, final float y, final FocusCallback callback) {
    if (mCamera == null) {
        return;
    }
    final Camera.Parameters params = mCamera.getParameters();
    Rect focusRect = calculateTapArea(x, y, 1f, context);
    mCamera.cancelAutoFocus();
    if (params.getMaxNumFocusAreas() > 0) {
        List<Camera.Area> focusAreas = new ArrayList<>();
        focusAreas.add(new Camera.Area(focusRect, 800));
        params.setFocusAreas(focusAreas);
    } else {
        Log.i(TAG, "focus areas not supported");
        callback.focusSuccess();
        return;
    }
    final String currentFocusMode = params.getFocusMode();
    params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    //        Log.i(TAG, "width = " + params.getPreviewSize().width + "height = " + params.getPreviewSize().height);
    mCamera.setParameters(params);
    mCamera.autoFocus(new Camera.AutoFocusCallback() {

        @Override
        public void onAutoFocus(boolean success, Camera camera) {
            if (success) {
                Camera.Parameters params = camera.getParameters();
                params.setFocusMode(currentFocusMode);
                camera.setParameters(params);
                callback.focusSuccess();
            } else {
                handleFocus(context, x, y, callback);
            }
        }
    });
}
Also used : Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) Camera(android.hardware.Camera)

Example 75 with Camera

use of android.hardware.Camera in project smartmodule by carozhu.

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)

Aggregations

Camera (android.hardware.Camera)154 Point (android.graphics.Point)28 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)25 Size (android.util.Size)25 IOException (java.io.IOException)19 Parameters (android.hardware.Camera.Parameters)18 Rect (android.graphics.Rect)17 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 Bitmap (android.graphics.Bitmap)8 MediaRecorder (android.media.MediaRecorder)7 OpenCamera (com.google.zxing.client.android.camera.open.OpenCamera)6 SuppressLint (android.annotation.SuppressLint)5 Area (android.hardware.Camera.Area)5