本文整理汇总了Java中android.hardware.Camera.Size方法的典型用法代码示例。如果您正苦于以下问题:Java Camera.Size方法的具体用法?Java Camera.Size怎么用?Java Camera.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.Camera
的用法示例。
在下文中一共展示了Camera.Size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBiggestPictureSize
import android.hardware.Camera; //导入方法依赖的package包/类
public static Camera.Size getBiggestPictureSize(
Camera.Parameters parameters) {
Camera.Size result = null;
for (Camera.Size size : parameters.getSupportedPictureSizes()) {
if (result == null) {
result = size;
} else {
int resultArea = result.width * result.height;
int newArea = size.width * size.height;
if (newArea > resultArea) {
result = size;
}
}
}
return (result);
}
示例2: getBestPreviewSize
import android.hardware.Camera; //导入方法依赖的package包/类
public static Camera.Size getBestPreviewSize(@NonNull List<Camera.Size> previewSizeList, int previewWidth, int previewHeight) {
Camera.Size bestPreviewSize = null;
for (Camera.Size previewSize : previewSizeList) {
if (bestPreviewSize != null) {
int diffBestPreviewWidth = Math.abs(bestPreviewSize.width - previewWidth);
int diffPreviewWidth = Math.abs(previewSize.width - previewWidth);
int diffBestPreviewHeight = Math.abs(bestPreviewSize.height - previewHeight);
int diffPreviewHeight = Math.abs(previewSize.height - previewHeight);
if (diffPreviewWidth + diffPreviewHeight < diffBestPreviewWidth + diffBestPreviewHeight) {
bestPreviewSize = previewSize;
}
} else {
bestPreviewSize = previewSize;
}
}
return bestPreviewSize;
}
示例3: findSuitableImageSize
import android.hardware.Camera; //导入方法依赖的package包/类
@NonNull
public static Point findSuitableImageSize(@NonNull Camera.Parameters parameters, int frameWidth, int frameHeight) {
List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
if (sizes != null && !sizes.isEmpty()) {
Collections.sort(sizes, new CameraSizeComparator());
float frameRatio = (float) frameWidth / (float) frameHeight;
for (Camera.Size size : sizes) {
int width = size.width;
int height = size.height;
if (width * height >= MIN_PREVIEW_PIXELS &&
Math.abs(frameRatio - (float) width / (float) height) <= MAX_DISTORTION) {
return new Point(width, height);
}
}
}
Camera.Size defaultSize = parameters.getPreviewSize();
if (defaultSize == null) {
throw new CodeScannerException("Unable to configure camera preview size");
}
return new Point(defaultSize.width, defaultSize.height);
}
示例4: takePicture
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* Initiates taking a picture, which happens asynchronously. The camera source should have been
* activated previously with {@link #start()} or {@link #start(SurfaceHolder)}. The camera
* preview is suspended while the picture is being taken, but will resume once picture taking is
* done.
*
* @param shutter the callback for image capture moment, or null
* @param jpeg the callback for JPEG image data, or null
*/
public void takePicture(ShutterCallback shutter, PictureCallback jpeg) {
synchronized (mCameraLock) {
if (mCamera != null) {
Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> supportedSizes = params.getSupportedPictureSizes();
/*for (Camera.Size s :supportedSizes){
Log.e("CAMERA_SIZE ", s.width+"/"+s.height);
}*/
Camera.Size sizePicture = supportedSizes.get(supportedSizes.size() - 1);
if ((supportedSizes.get(supportedSizes.size() - 1).height < supportedSizes.get(0).height) || (supportedSizes.get(supportedSizes.size() - 1).width < supportedSizes.get(0).width)) {
for (int i = supportedSizes.size() - 2; i > 3; i--) {
if (((float) supportedSizes.get(i).width / (float) supportedSizes.get(i).height) < 1.4) {
sizePicture = supportedSizes.get(i);
}
}
} else {
for (int i = 1; i < supportedSizes.size() - 3; i++) {
if (((float) supportedSizes.get(i).width / (float) supportedSizes.get(i).height) < 1.4) {
sizePicture = supportedSizes.get(i);
}
}
}
Log.e("CAMERA_SIZE ", sizePicture.width + "/" + sizePicture.height);
params.setPictureSize(sizePicture.width, sizePicture.height);
mCamera.setParameters(params);
PictureStartCallback startCallback = new PictureStartCallback();
startCallback.mDelegate = shutter;
PictureDoneCallback doneCallback = new PictureDoneCallback();
doneCallback.mDelegate = jpeg;
mCamera.takePicture(startCallback, null, null, doneCallback);
}
}
}
示例5: getOptimalPictureSize
import android.hardware.Camera; //导入方法依赖的package包/类
private Camera.Size getOptimalPictureSize(final int width, final int height, final Camera.Size previewSize, final List<Camera.Size> supportedSizes){
/*
get the supportedPictureSize that:
- matches exactly width and height
- has the closest aspect ratio to the preview aspect ratio
- has picture.width and picture.height closest to width and height
- has the highest supported picture width and height up to 2 Megapixel if width == 0 || height == 0
*/
Camera.Size size = mCamera.new Size(width, height);
// convert to landscape if necessary
if (size.width < size.height) {
int temp = size.width;
size.width = size.height;
size.height = temp;
}
double previewAspectRatio = (double)previewSize.width / (double)previewSize.height;
if (previewAspectRatio < 1.0) {
// reset ratio to landscape
previewAspectRatio = 1.0 / previewAspectRatio;
}
Log.d(TAG, "CameraPreview previewAspectRatio " + previewAspectRatio);
double aspectTolerance = 0.1;
double bestDifference = Double.MAX_VALUE;
for (int i = 0; i < supportedSizes.size(); i++) {
Camera.Size supportedSize = supportedSizes.get(i);
// Perfect match
if (supportedSize.equals(size)) {
Log.d(TAG, "CameraPreview optimalPictureSize " + supportedSize.width + 'x' + supportedSize.height);
return supportedSize;
}
double difference = Math.abs(previewAspectRatio - ((double)supportedSize.width / (double)supportedSize.height));
if (difference < bestDifference - aspectTolerance) {
// better aspectRatio found
if ((width != 0 && height != 0) || (supportedSize.width * supportedSize.height < 2048 * 1024)) {
size.width = supportedSize.width;
size.height = supportedSize.height;
bestDifference = difference;
}
} else if (difference < bestDifference + aspectTolerance) {
// same aspectRatio found (within tolerance)
if (width == 0 || height == 0) {
// set highest supported resolution below 2 Megapixel
if ((size.width < supportedSize.width) && (supportedSize.width * supportedSize.height < 2048 * 1024)) {
size.width = supportedSize.width;
size.height = supportedSize.height;
}
} else {
// check if this pictureSize closer to requested width and height
if (Math.abs(width * height - supportedSize.width * supportedSize.height) < Math.abs(width * height - size.width * size.height)) {
size.width = supportedSize.width;
size.height = supportedSize.height;
}
}
}
}
Log.d(TAG, "CameraPreview optimalPictureSize " + size.width + 'x' + size.height);
return size;
}
示例6: setDesiredCameraParameters
import android.hardware.Camera; //导入方法依赖的package包/类
public void setDesiredCameraParameters(Camera camera, boolean safeMode) {
Camera.Parameters parameters = camera.getParameters();
if (parameters == null) {
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
return;
}
Log.i(TAG, "Initial camera parameters: " + parameters.flatten());
if (safeMode) {
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
}
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
camera.setParameters(parameters);
Camera.Parameters afterParameters = camera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize();
if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize
.height)) {
Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' +
cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x'
+ afterSize.height);
cameraResolution.x = afterSize.width;
cameraResolution.y = afterSize.height;
}
/** 设置相机预览为竖屏 */
camera.setDisplayOrientation(90);
}
示例7: runMainHanlder
import android.hardware.Camera; //导入方法依赖的package包/类
private void runMainHanlder(final Camera.Size previewSize) {
Handler mainHanlder = new Handler(Looper.getMainLooper());
mainHanlder.post(new Runnable() {
@Override
public void run() {
adjustViewSize(previewSize);
}
});
}
示例8: adjustPreviewLayout
import android.hardware.Camera; //导入方法依赖的package包/类
public void adjustPreviewLayout(int type) {
Camera camera = _cameras.get(type);
if (null == camera) {
return;
}
CameraInfoWrapper cameraInfo = _cameraInfos.get(type);
int displayRotation;
int rotation;
int orientation = cameraInfo.info.orientation;
if (cameraInfo.info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
rotation = (orientation + _actualDeviceOrientation * 90) % 360;
displayRotation = (720 - orientation - _actualDeviceOrientation * 90) % 360;
} else {
rotation = (orientation - _actualDeviceOrientation * 90 + 360) % 360;
displayRotation = rotation;
}
cameraInfo.rotation = rotation;
// TODO: take in account the _orientation prop
setAdjustedDeviceOrientation(rotation);
camera.setDisplayOrientation(displayRotation);
Camera.Parameters parameters = camera.getParameters();
parameters.setRotation(cameraInfo.rotation);
// set preview size
// defaults to highest resolution available
Camera.Size optimalPreviewSize = getBestSize(parameters.getSupportedPreviewSizes(), Integer.MAX_VALUE, Integer.MAX_VALUE);
int width = optimalPreviewSize.width;
int height = optimalPreviewSize.height;
parameters.setPreviewSize(width, height);
try {
camera.setParameters(parameters);
} catch (Exception e) {
e.printStackTrace();
}
if (cameraInfo.rotation == 0 || cameraInfo.rotation == 180) {
cameraInfo.previewWidth = width;
cameraInfo.previewHeight = height;
} else {
cameraInfo.previewWidth = height;
cameraInfo.previewHeight = width;
}
}
示例9: getWidth
import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public int getWidth(Object obj) {
Camera.Size size = (Camera.Size) obj;
return size.width;
}
示例10: getHeight
import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public int getHeight(Object obj) {
Camera.Size size = (Camera.Size) obj;
return size.height;
}
示例11: compare
import android.hardware.Camera; //导入方法依赖的package包/类
public int compare(Camera.Size size1, Camera.Size size2) {
return size2.width - size1.width;
}
示例12: setDesiredCameraParameters
import android.hardware.Camera; //导入方法依赖的package包/类
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
Camera.Parameters parameters = camera.getParameters();
if (parameters == null) {
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
return;
}
Log.i(TAG, "Initial camera parameters: " + parameters.flatten());
if (safeMode) {
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
initializeTorch(parameters, prefs, safeMode);
CameraConfigurationUtils.setFocus(
parameters,
prefs.getBoolean(PerferenceKey.KEY_AUTO_FOCUS, true),
prefs.getBoolean(PerferenceKey.KEY_DISABLE_CONTINUOUS_FOCUS, true),
safeMode);
if (!safeMode) {
if (prefs.getBoolean(PerferenceKey.KEY_INVERT_SCAN, false)) {
CameraConfigurationUtils.setInvertColor(parameters);
}
if (!prefs.getBoolean(PerferenceKey.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
CameraConfigurationUtils.setBarcodeSceneMode(parameters);
}
if (!prefs.getBoolean(PerferenceKey.KEY_DISABLE_METERING, true)) {
CameraConfigurationUtils.setVideoStabilization(parameters);
CameraConfigurationUtils.setFocusArea(parameters);
CameraConfigurationUtils.setMetering(parameters);
}
}
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
Log.i(TAG, "Final camera parameters: " + parameters.flatten());
camera.setParameters(parameters);
setDisplayOrientation(camera, 90);
Camera.Parameters afterParameters = camera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize();
if (afterSize!= null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y +
", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
cameraResolution.x = afterSize.width;
cameraResolution.y = afterSize.height;
}
}
示例13: onPreviewSizeSelected
import android.hardware.Camera; //导入方法依赖的package包/类
@Override
public Camera.Size onPreviewSizeSelected(List<Camera.Size> list) {
return null;
}
示例14: getHeight
import android.hardware.Camera; //导入方法依赖的package包/类
public int getHeight(Object obj) {
Camera.Size size = (Camera.Size) obj;
return size.height;
}