You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CameraView/docs/_posts/2018-12-20-capture-size.md

109 lines
4.1 KiB

---
layout: page
title: "Capture Size"
description: "Set size of output media"
category: docs
Metering APIs (#580) * Add cameraPictureMetering and cameraPictureSnapshotMetering * Adapt Meter and metering package to picture use * Simplify Full2PictureRecorder, we'll use metering package instead * Add doMetering parameter * Implement cameraPictureMetering and cameraPictureSnapshotMetering in engine * Add options in demo app * Add better logs * Add Snapshot2PictureRecorder * Capture the correct frame based on timestamp * Lock AE and AWB. Account for captureBuilder changes * Fix runtime flash changes bug * Small changes * Flash support for metered snapshots * Remove AE and AWB locks * Lock AE/AWB/AF inside the snapshot recorder * Small changes * Fix AutoExposure metering * Create Locker and locking.* parameters * Implement Locker in Camera2Engine * Implement reset delay in Camera2Engine instead of Meter * Simplify Snapshot2PictureRecorder * Fix success value * Unlock inside Camera2Engine * Do not lock for normal gestures * Simplify logic * Improve locking/AutoFocus * Fix TORCH bug * Small changes to locking and metering * Remove AF and AWB for testing * Create action package * Create OneShotAction * Create LogAction * Revisit Full2VideoRecorder using actions * Revisit Full2PictureRecorder using actions * Enable missing functionality in Snapshot2PictureRecorder * Move Snapshot2PictureRecorder using actions, rewrite lock package * Add TimeoutAction * Add comments to the action package * Add meter package * Remove old metering package * Fix various bugs * Add action.abort() * Abort old MeterAction when running new ones * Fix various bugs * Add doc empty page * Add documentation * Fix tests
5 years ago
order: 9
date: 2018-12-20 22:07:22
6 years ago
disqus: 1
---
If you are planning to use the snapshot APIs, the size of the media output is that of the preview stream,
accounting for any cropping made when [measuring the view](preview-size) and other constraints.
Please read the [Snapshot Size](snapshot-size) document.
If you are planning to use the standard APIs, then what follows applies.
### Controlling Size
Size is controlled using `setPictureSize` and `setVideoSize` for, respectively, picture and video
output. These method will accept a `SizeSelector`. The point of a `SizeSelector` is to analyze the
available sizes that the sensor offers, and choose the ones it prefers.
```java
// This will be the size of pictures taken with takePicture().
cameraView.setPictureSize(new SizeSelector() {
@Override
public List<Size> select(List<Size> source) {
// Receives a list of available sizes.
// Must return a list of acceptable sizes.
}
});
// This will be the size of videos taken with takeVideo().
cameraView.setVideoSize(new SizeSelector() {
@Override
public List<Size> select(List<Size> source) {
// Same here.
}
});
```
In practice, this is way easier using XML attributes or leveraging the `SizeSelectors` utilities.
### XML attributes
```xml
<com.otaliastudios.cameraview.CameraView
app:cameraPictureSizeMinWidth="100"
app:cameraPictureSizeMinHeight="100"
app:cameraPictureSizeMaxWidth="3000"
app:cameraPictureSizeMaxHeight="3000"
app:cameraPictureSizeMinArea="10000000"
app:cameraPictureSizeMaxArea="50000000"
app:cameraPictureSizeAspectRatio="1:1"
app:cameraPictureSizeSmallest="true|false"
app:cameraPictureSizeBiggest="true|false"
app:cameraVideoSizeMinWidth="100"
app:cameraVideoSizeMinHeight="100"
app:cameraVideoSizeMaxWidth="3000"
app:cameraVideoSizeMaxHeight="3000"
app:cameraVideoSizeMinArea="10000000"
app:cameraVideoSizeMaxArea="50000000"
app:cameraVideoSizeAspectRatio="1:1"
app:cameraVideoSizeSmallest="true|false"
app:cameraVideoSizeBiggest="true|false"
/>
```
The `cameraPicture*` attributes are used in picture mode, while the `cameraVideo*` attributes are used in video mode.
Note that, for each mode, if you declare more than one XML constraint, the resulting selector will try
to match **all** the constraints. Be careful - it is very likely that applying lots of constraints will give empty results.
### SizeSelectors utilities
All these XML attrs are actually shorthands to some `SizeSelectors` utility method.
For more versatility, or to address selection issues with multiple constraints,
we encourage you to use `SizeSelectors` to get a selector, and then apply it to the `CameraView` as seen.
The utilities will even let you merge different selectors with `or` or `and` logic, in a very
intuitive way. For example:
```java
SizeSelector width = SizeSelectors.minWidth(1000);
SizeSelector height = SizeSelectors.minHeight(2000);
SizeSelector dimensions = SizeSelectors.and(width, height); // Matches sizes bigger than 1000x2000.
SizeSelector ratio = SizeSelectors.aspectRatio(AspectRatio.of(1, 1), 0); // Matches 1:1 sizes.
SizeSelector result = SizeSelectors.or(
SizeSelectors.and(ratio, dimensions), // Try to match both constraints
ratio, // If none is found, at least try to match the aspect ratio
SizeSelectors.biggest() // If none is found, take the biggest
);
camera.setPictureSize(result);
camera.setVideoSize(result);
```
This selector will try to find square sizes bigger than 1000x2000. If none is found, it falls back
to just square sizes.
### Related APIs
|Method|Description|
|------|-----------|
|`setPictureSize(SizeSelector)`|Provides a size selector for the capture size in `PICTURE` mode.|
|`setVideoSize(SizeSelector)`|Provides a size selector for the capture size in `VIDEO` mode.|
|`getPictureSize()`|Returns the size of the output picture, including any rotation. Returns null in `VIDEO` mode.|
|`getVideoSize()`|Returns the size of the output video, including any rotation. Returns null in `PICTURE` mode.|