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);
}
}
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;
}
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 **/
}
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);
}
}
});
}
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;
}
Aggregations