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