use of android.hardware.Camera.Size in project UltimateAndroid by cymcsg.
the class CameraPreviewInput method setRenderSizeToCameraSize.
private void setRenderSizeToCameraSize() {
Parameters params = camera.getParameters();
Size previewSize = params.getPreviewSize();
setRenderSize(previewSize.width, previewSize.height);
}
use of android.hardware.Camera.Size in project UltimateAndroid by cymcsg.
the class CameraPreviewInput method setRenderSizeToCameraSize.
private void setRenderSizeToCameraSize() {
Parameters params = camera.getParameters();
Size previewSize = params.getPreviewSize();
setRenderSize(previewSize.width, previewSize.height);
}
use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.
the class CameraUtils method getPreferredPreviewSize.
/*
* modified from: https://github.com/commonsguy/cwac-camera/blob/master/camera/src/com/commonsware/cwac/camera/CameraUtils.java
*/
@Nullable
public static Size getPreferredPreviewSize(int displayOrientation, int width, int height, @NonNull Parameters parameters) {
final int targetWidth = displayOrientation % 180 == 90 ? height : width;
final int targetHeight = displayOrientation % 180 == 90 ? width : height;
final double targetRatio = (double) targetWidth / targetHeight;
Log.w(TAG, String.format("getPreferredPreviewSize(%d, %d, %d) -> target %dx%d, AR %.02f", displayOrientation, width, height, targetWidth, targetHeight, targetRatio));
List<Size> sizes = parameters.getSupportedPreviewSizes();
List<Size> ideals = new LinkedList<>();
List<Size> bigEnough = new LinkedList<>();
for (Size size : sizes) {
Log.w(TAG, String.format(" %dx%d (%.02f)", size.width, size.height, (float) size.width / size.height));
if (size.height == size.width * targetRatio && size.height >= targetHeight && size.width >= targetWidth) {
ideals.add(size);
Log.w(TAG, " (ideal ratio)");
} else if (size.width >= targetWidth && size.height >= targetHeight) {
bigEnough.add(size);
Log.w(TAG, " (good size, suboptimal ratio)");
}
}
if (!ideals.isEmpty())
return Collections.min(ideals, new AreaComparator());
else if (!bigEnough.isEmpty())
return Collections.min(bigEnough, new AspectRatioComparator(targetRatio));
else
return Collections.max(sizes, new AreaComparator());
}
use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.
the class CameraView method startPreview.
private void startPreview(@NonNull final Parameters parameters) {
if (this.camera.isPresent()) {
try {
final Camera camera = this.camera.get();
final Size preferredPreviewSize = getPreferredPreviewSize(parameters);
if (preferredPreviewSize != null && !parameters.getPreviewSize().equals(preferredPreviewSize)) {
Log.w(TAG, "starting preview with size " + preferredPreviewSize.width + "x" + preferredPreviewSize.height);
if (state == State.ACTIVE)
stopPreview();
previewSize = preferredPreviewSize;
parameters.setPreviewSize(preferredPreviewSize.width, preferredPreviewSize.height);
camera.setParameters(parameters);
} else {
previewSize = parameters.getPreviewSize();
}
long previewStartMillis = System.currentTimeMillis();
camera.startPreview();
Log.w(TAG, "camera.startPreview() -> " + (System.currentTimeMillis() - previewStartMillis) + "ms");
state = State.ACTIVE;
Util.runOnMain(new Runnable() {
@Override
public void run() {
requestLayout();
for (CameraViewListener listener : listeners) {
listener.onCameraStart();
}
}
});
} catch (Exception e) {
Log.w(TAG, e);
}
}
}
use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.
the class CameraView method setPreviewCallback.
public void setPreviewCallback(@NonNull final PreviewCallback previewCallback) {
enqueueTask(new PostInitializationTask<Void>() {
@Override
protected void onPostMain(Void avoid) {
if (camera.isPresent()) {
camera.get().setPreviewCallback(new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (!CameraView.this.camera.isPresent()) {
return;
}
final int rotation = getCameraPictureOrientation();
final Size previewSize = camera.getParameters().getPreviewSize();
if (data != null) {
previewCallback.onPreviewFrame(new PreviewFrame(data, previewSize.width, previewSize.height, rotation));
}
}
});
}
}
});
}
Aggregations