本文整理汇总了Java中android.hardware.camera2.params.StreamConfigurationMap类的典型用法代码示例。如果您正苦于以下问题:Java StreamConfigurationMap类的具体用法?Java StreamConfigurationMap怎么用?Java StreamConfigurationMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamConfigurationMap类属于android.hardware.camera2.params包,在下文中一共展示了StreamConfigurationMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectCameraInfo
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
/**
* <p>Collects some information from {@link #mCameraCharacteristics}.</p>
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
* {@link #mAspectRatio}.</p>
*/
private void collectCameraInfo() {
StreamConfigurationMap map = mCameraCharacteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
throw new IllegalStateException("Failed to get configuration map: " + mCameraId);
}
mPreviewSizes.clear();
for (android.util.Size size : map.getOutputSizes(mPreview.getOutputClass())) {
mPreviewSizes.add(new Size(size.getWidth(), size.getHeight()));
}
mPictureSizes.clear();
collectPictureSizes(mPictureSizes, map);
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
mAspectRatio = mPreviewSizes.ratios().iterator().next();
}
}
示例2: open
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
public void open() {
try {
CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mCameraSize = map.getOutputSizes(SurfaceTexture.class)[0];
HandlerThread thread = new HandlerThread("OpenCamera");
thread.start();
Handler backgroundHandler = new Handler(thread.getLooper());
manager.openCamera(cameraId, mCameraDeviceCallback, null);
// カメラの物理的な情報を得る
mCameraCharacteristics = manager.getCameraCharacteristics( cameraId );
return;
}
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例3: collectRatioSizes
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
@Override
public void collectRatioSizes() {
ratioSizeList.clear();
CameraCharacteristics characteristics;
StreamConfigurationMap map = null;
try {
characteristics = ((CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE)).getCameraCharacteristics(Integer.toString(Integer.parseInt(getCameraId())));
map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
} catch (CameraAccessException e) {
e.printStackTrace();
}
Size[] outputSizes = map.getOutputSizes(SurfaceTexture.class);
if (outputSizes != null) {
List<Double> ratioList = new ArrayList<>();
for (Size size : outputSizes) {
double ratio = (double) size.getWidth() / (double) size.getHeight();
if (!ratioList.contains(ratio)) {
ratioList.add(ratio);
ratioSizeList.add(new AspectRatio(ratio, size.getWidth(), size.getHeight()));
}
}
}
}
示例4: startPreview
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
private void startPreview() {
try {
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size previewSize = Util.getPreferredPreviewSize(
configMap.getOutputSizes(ImageFormat.JPEG),textureView.getWidth(), textureView.getHeight());
surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
Surface surface = new Surface(surfaceTexture);
captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureBuilder.addTarget(surface);
cameraDevice.createCaptureSession(Arrays.asList(surface),captureSessionCallback,backgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例5: getSupportedSize
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
@Override
protected List<PreviewSize> getSupportedSize() {
try {
CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(
getCurrentCameraId());
StreamConfigurationMap map =
characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
return Collections.singletonList(new PreviewSize(mPreviewWidth, mPreviewHeight));
}
Size[] supportedSize = map.getOutputSizes(SurfaceTexture.class);
if (supportedSize == null || supportedSize.length == 0) {
return Collections.singletonList(new PreviewSize(mPreviewWidth, mPreviewHeight));
}
List<PreviewSize> results = new ArrayList<>();
for (Size size : supportedSize) {
results.add(new PreviewSize(size.getWidth(), size.getHeight()));
}
return results;
} catch (CameraAccessException e) {
throw new CameraAccessError();
}
}
示例6: getSizes
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
private List<Size> getSizes(StreamConfigurationMap map) {
Size[] sizes = map.getOutputSizes(MediaRecorder.class);
// StreamConfigurationMap.getOutputSizes(MediaRecorder.class) only tells us if the
// camera supports these sizes. It does not tell us if MediaRecorder supports these
// sizes, odd as that sounds. Therefore, we need to filter ourselves manually.
List<Size> filtered;
if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_2160P)) {
filtered = filter(sizes, SIZE_4K);
if (!filtered.isEmpty()) {
return filtered;
}
}
if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_1080P)) {
filtered = filter(sizes, SIZE_1080P);
if (!filtered.isEmpty()) {
return filtered;
}
}
if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_720P)) {
filtered = filter(sizes, SIZE_720P);
if (!filtered.isEmpty()) {
return filtered;
}
}
if (CamcorderProfile.hasProfile(getCameraId(), CamcorderProfile.QUALITY_480P)) {
filtered = filter(sizes, SIZE_480P);
if (!filtered.isEmpty()) {
return filtered;
}
}
return Arrays.asList(sizes);
}
示例7: initialize
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
@Override
void initialize(StreamConfigurationMap map) {
if (DEBUG) Log.d(TAG, "Initializing PreviewSession");
super.initialize(chooseOptimalSize(getSizes(map), mCameraView.getWidth(), mCameraView.getHeight()));
SurfaceTexture texture = mCameraView.getSurfaceTexture();
if (texture == null) {
// This will be caught in Camera2Module.setSession
throw new IllegalStateException(
"Expected a SurfaceTexture to exist, but none does. "
+ "Was the SurfaceTexture already closed?");
}
texture.setDefaultBufferSize(getWidth(), getHeight());
// This is the output Surface we need to start the preview.
mSurface = new Surface(texture);
}
示例8: findBestPreviewSize
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
private static Size findBestPreviewSize(@NonNull StreamConfigurationMap scMap, int width, int height) {
List<Size> sizes = new ArrayList<>(Arrays.asList(scMap.getOutputSizes(SurfaceTexture.class)));
for (Iterator<Size> itr = sizes.iterator(); itr.hasNext(); ) {
Size size = itr.next();
if (size.getWidth() < width || size.getHeight() < height) {
itr.remove();
}
}
if (sizes.size() == 0) {
sizes = new ArrayList<>(Arrays.asList(scMap.getOutputSizes(SurfaceTexture.class)));
}
Collections.sort(sizes, new Comparator<Size>() {
@Override
public int compare(Size s1, Size s2) {
return s2.getWidth() * s2.getHeight() - s1.getWidth() * s1.getHeight();
}
});
return (sizes.size() > 0) ? sizes.get(sizes.size() - 1) : null;
}
示例9: getDefaultPictureSize
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
/**
* @return The largest supported picture size.
*/
public Size getDefaultPictureSize() {
StreamConfigurationMap configs = mCharacteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
android.util.Size[] supportedSizes = configs.getOutputSizes(sCaptureImageFormat);
// Find the largest supported size.
android.util.Size largestSupportedSize = supportedSizes[0];
long largestSupportedSizePixels = largestSupportedSize.getWidth()
* largestSupportedSize.getHeight();
for (int i = 0; i < supportedSizes.length; i++) {
long numPixels = supportedSizes[i].getWidth() * supportedSizes[i].getHeight();
if (numPixels > largestSupportedSizePixels) {
largestSupportedSize = supportedSizes[i];
largestSupportedSizePixels = numPixels;
}
}
return new Size(largestSupportedSize.getWidth(),
largestSupportedSize.getHeight());
}
示例10: chooseCamera
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
private String chooseCamera() {
final CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
for (final String cameraId : manager.getCameraIdList()) {
final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
// We don't use a front facing camera in this sample.
final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
final StreamConfigurationMap map =
characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (map == null) {
continue;
}
useCamera2API = isHardwareLevelSupported(characteristics,
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
LOGGER.i("Camera API lv2?: %s", useCamera2API);
return cameraId;
}
} catch (CameraAccessException e) {
LOGGER.e(e, "Not allowed to access camera");
}
return null;
}
示例11: collectPictureSizes
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
@Override
protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
// Try to get hi-res output sizes
android.util.Size[] outputSizes = map.getHighResolutionOutputSizes(ImageFormat.JPEG);
if (outputSizes != null) {
for (android.util.Size size : map.getHighResolutionOutputSizes(ImageFormat.JPEG)) {
sizes.add(new Size(size.getWidth(), size.getHeight()));
}
}
if (sizes.isEmpty()) {
super.collectPictureSizes(sizes, map);
}
}
示例12: configureSurfaces
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
/**
* Configure the surfaceview and RS processing.
*/
private void configureSurfaces() {
// Find a good size for output - largest 16:9 aspect ratio that's less than 720p
final int MAX_WIDTH = 1280;
final float TARGET_ASPECT = 16.f / 9.f;
final float ASPECT_TOLERANCE = 0.1f;
StreamConfigurationMap configs =
mCameraInfo.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] outputSizes = configs.getOutputSizes(SurfaceHolder.class);
Size outputSize = outputSizes[0];
float outputAspect = (float) outputSize.getWidth() / outputSize.getHeight();
for (Size candidateSize : outputSizes) {
if (candidateSize.getWidth() > MAX_WIDTH)
continue;
float candidateAspect = (float) candidateSize.getWidth() / candidateSize.getHeight();
boolean goodCandidateAspect =
Math.abs(candidateAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
boolean goodOutputAspect = Math.abs(outputAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
if ((goodCandidateAspect && !goodOutputAspect) ||
candidateSize.getWidth() > outputSize.getWidth()) {
outputSize = candidateSize;
outputAspect = candidateAspect;
}
}
Log.i(TAG, "Resolution chosen: " + outputSize);
setupProcessing(outputSize);
// this will trigger onSurfaceChanged()
getViewfinderSurfaceView().getHolder()
.setFixedSize(outputSize.getWidth(), outputSize.getHeight());
getViewfinderSurfaceView().setAspectRatio(outputAspect);
}
示例13: setFragmentPreviewSize
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
/**
* Sets the preview size of the fragment
* @param width The width of available size for camera preview
* @param height The height of available size for camera preview
* @param swappedDimensions - boolean indicating if dimensions need to be swapped
* @param map - Configurationmap of the camera
* @return mPreviewSize - the previewsize that is set in the fragment
*/
private Size setFragmentPreviewSize(int width, int height, boolean swappedDimensions, StreamConfigurationMap map) {
// For still image captures, we use the largest available size.
Size largest = Collections.max(
Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
new CameraFragmentUtil.CompareSizesByArea());
Point displaySize = new Point();
fragment.getActivity().getWindowManager().getDefaultDisplay().getSize(displaySize);
int rotatedPreviewWidth = width;
int rotatedPreviewHeight = height;
int maxPreviewWidth = displaySize.x;
int maxPreviewHeight = displaySize.y;
if (swappedDimensions) {
rotatedPreviewWidth = height;
rotatedPreviewHeight = width;
maxPreviewWidth = displaySize.y;
maxPreviewHeight = displaySize.x;
}
if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
maxPreviewWidth = MAX_PREVIEW_WIDTH;
}
if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
maxPreviewHeight = MAX_PREVIEW_HEIGHT;
}
// Attempting to use too large a preview size could exceed the camera bus' bandwidth
// limitation, resulting in gorgeous previews but the storage of garbage capture data.
Size mPreviewSize = CameraFragmentUtil.chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
maxPreviewHeight, largest);
fragment.setPreviewSize(mPreviewSize);
return mPreviewSize;
}
示例14: getCameraResolutionsBack
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
public Size[] getCameraResolutionsBack() {
try {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics("0");
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
!= CameraCharacteristics.LENS_FACING_BACK) {
cameraCharacteristics = cameraManager.getCameraCharacteristics("1");
}
StreamConfigurationMap streamConfigurationMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
return streamConfigurationMap.getOutputSizes(SurfaceTexture.class);
} catch (CameraAccessException e) {
Log.e(TAG, e.getMessage());
return new Size[0];
}
}
示例15: getCameraResolutionsFront
import android.hardware.camera2.params.StreamConfigurationMap; //导入依赖的package包/类
public Size[] getCameraResolutionsFront() {
try {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics("0");
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
!= CameraCharacteristics.LENS_FACING_FRONT) {
cameraCharacteristics = cameraManager.getCameraCharacteristics("1");
}
StreamConfigurationMap streamConfigurationMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
return streamConfigurationMap.getOutputSizes(SurfaceTexture.class);
} catch (CameraAccessException e) {
Log.e(TAG, e.getMessage());
return new Size[0];
}
}