本文整理匯總了Java中android.util.Size類的典型用法代碼示例。如果您正苦於以下問題:Java Size類的具體用法?Java Size怎麽用?Java Size使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Size類屬於android.util包,在下文中一共展示了Size類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import android.util.Size; //導入依賴的package包/類
/**
* Initialize HeifReader module.
*
* @param context Context.
*/
public static void initialize(Context context) {
mRenderScript = RenderScript.create(context);
mCacheDir = context.getCacheDir();
// find best HEVC decoder
mDecoderName = null;
mDecoderSupportedSize = new Size(0, 0);
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (codecInfo.isEncoder()) {
continue;
}
for (String type : codecInfo.getSupportedTypes()) {
if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
+ " supported-size=" + supportedSize
+ " color-formats=" + Arrays.toString(cap.colorFormats)
);
if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
mDecoderName = codecInfo.getName();
mDecoderSupportedSize = supportedSize;
}
}
}
}
if (mDecoderName == null) {
throw new RuntimeException("no HEVC decoding support");
}
Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
示例2: setFragment
import android.util.Size; //導入依賴的package包/類
protected void setFragment() {
final Fragment fragment =
CameraConnectionFragment.newInstance(
new CameraConnectionFragment.ConnectionCallback() {
@Override
public void onPreviewSizeChosen(final Size size, final int rotation) {
CameraActivity.this.onPreviewSizeChosen(size, rotation);
}
},
this,
getLayoutId(),
getDesiredPreviewFrameSize());
getFragmentManager()
.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
示例3: chooseOptimalSize
import android.util.Size; //導入依賴的package包/類
/**
* Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
* width and height are at least as large as the respective requested values, and whose aspect
* ratio matches with the specified value.
*
* @param choices The list of sizes that the camera supports for the intended output class
* @param width The minimum desired width
* @param height The minimum desired height
* @param aspectRatio The aspect ratio
* @return The optimal {@code Size}, or an arbitrary one if none were big enough
*/
private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) {
// Collect the supported resolutions that are at least as big as the preview Surface
List<Size> bigEnough = new ArrayList<Size>();
int w = aspectRatio.getWidth();
int h = aspectRatio.getHeight();
for (Size option : choices) {
if (option.getHeight() == option.getWidth() * h / w &&
option.getWidth() >= width && option.getHeight() >= height) {
bigEnough.add(option);
}
}
// Pick the smallest of those, assuming we found any
if (bigEnough.size() > 0) {
return Collections.min(bigEnough, new CompareSizesByArea());
} else {
Log.e(TAG, "Couldn't find any suitable preview size");
return choices[0];
}
}
示例4: startPreview
import android.util.Size; //導入依賴的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: chooseOptimalSize
import android.util.Size; //導入依賴的package包/類
/**
* Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
* width and height are at least as large as the respective requested values, and whose aspect
* ratio matches with the specified value.
*
* @param choices The list of sizes that the camera supports for the intended output class
* @param width The minimum desired width
* @param height The minimum desired height
* @param aspectRatio The aspect ratio
* @return The optimal {@code Size}, or an arbitrary one if none were big enough
*/
@SuppressLint("LongLogTag")
@DebugLog
private static Size chooseOptimalSize(
final Size[] choices, final int width, final int height, final Size aspectRatio) {
// Collect the supported resolutions that are at least as big as the preview Surface
final List<Size> bigEnough = new ArrayList<Size>();
for (final Size option : choices) {
if (option.getHeight() >= MINIMUM_PREVIEW_SIZE && option.getWidth() >= MINIMUM_PREVIEW_SIZE) {
Timber.tag(TAG).i("Adding size: " + option.getWidth() + "x" + option.getHeight());
bigEnough.add(option);
} else {
Timber.tag(TAG).i("Not adding size: " + option.getWidth() + "x" + option.getHeight());
}
}
// Pick the smallest of those, assuming we found any
if (bigEnough.size() > 0) {
final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea());
Timber.tag(TAG).i("Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight());
return chosenSize;
} else {
Timber.tag(TAG).e("Couldn't find any suitable preview size");
return choices[0];
}
}
示例6: chooseOptimalSize
import android.util.Size; //導入依賴的package包/類
/**
* Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
* width and height are at least as large as the respective requested values, and whose aspect
* ratio matches with the specified value.
*
* @param choices The list of sizes that the camera supports for the intended output class
* @param width The minimum desired width
* @param height The minimum desired height
* @param aspectRatio The aspect ratio
* @return The optimal {@code Size}, or an arbitrary one if none were big enough
*/
private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) {
// Collect the supported resolutions that are at least as big as the preview Surface
List<Size> bigEnough = new ArrayList<>();
int w = aspectRatio.getWidth();
int h = aspectRatio.getHeight();
for (Size option : choices) {
if (option.getHeight() == option.getWidth() * h / w &&
option.getWidth() >= width && option.getHeight() >= height) {
bigEnough.add(option);
}
}
// Pick the smallest of those, assuming we found any
if (bigEnough.size() > 0) {
return Collections.min(bigEnough, new CompareSizesByArea());
} else {
Log.e(TAG, "Couldn't find any suitable preview size");
return choices[0];
}
}
示例7: runCameraLiveView
import android.util.Size; //導入依賴的package包/類
public void runCameraLiveView() {
final Fragment cameraView = CameraConnectionFragment.newInstance(
new CameraConnectionFragment.ConnectionCallback() {
@Override
public void onPreviewSizeChosen(Size size, int rotation) {
MainActivity.this.onPreviewSizeChosen(size);
}
},
this,
R.layout.placerecognizer_ui,
new Size(mImageClassifier.getImageWidth(), mImageClassifier.getImageHeight())
);
getFragmentManager().beginTransaction()
.replace(R.id.container, cameraView)
.commit();
}
示例8: onPreviewSizeChosen
import android.util.Size; //導入依賴的package包/類
public void onPreviewSizeChosen(final Size size, final int rotation) {
previewWidth = size.getWidth();
previewHeight = size.getHeight();
final Display display = getWindowManager().getDefaultDisplay();
final int screenOrientation = display.getRotation();
LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation);
sensorOrientation = rotation + screenOrientation;
LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight);
rgbBytes = new int[previewWidth * previewHeight];
rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888);
croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Bitmap.Config.ARGB_8888);
frameToCropTransform =
ImageUtils.getTransformationMatrix(previewWidth, previewHeight, INPUT_SIZE, INPUT_SIZE,
sensorOrientation, MAINTAIN_ASPECT);
Matrix cropToFrameTransform = new Matrix();
frameToCropTransform.invert(cropToFrameTransform);
yuvBytes = new byte[3][];
}
示例9: chooseOptimalSize
import android.util.Size; //導入依賴的package包/類
private static Size chooseOptimalSize(
final Size[] choices, final int width, final int height, final Size aspectRatio) {
// Collect the supported resolutions that are at least as big as the preview Surface
final List<Size> bigEnough = new ArrayList<>();
for (final Size option : choices) {
if (option.getHeight() >= MINIMUM_PREVIEW_SIZE && option.getWidth() >= MINIMUM_PREVIEW_SIZE) {
Log.i(TAG, "Adding size: " + option.getWidth() + "x" + option.getHeight());
bigEnough.add(option);
} else {
Log.i(TAG, "Not adding size: " + option.getWidth() + "x" + option.getHeight());
}
}
// Pick the smallest of those, assuming we found any
if (bigEnough.size() > 0) {
final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea());
Log.i(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight());
return chosenSize;
} else {
Log.e(TAG, "Couldn't find any suitable preview size");
return choices[0];
}
}
示例10: collectRatioSizes
import android.util.Size; //導入依賴的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()));
}
}
}
}
示例11: configureTextureView
import android.util.Size; //導入依賴的package包/類
/**
* configures the ProportionalTextureView to respect the aspect ratio of the image and using an appropriate buffer size
*/
@VisibleForTesting
void configureTextureView(@NonNull ProportionalTextureView textureView, @ConfigurationOrientation int deviceOrientation,
@SurfaceRotation int relativeDisplayRotation, @NonNull Size previewSize) {
switch (deviceOrientation) {
case Configuration.ORIENTATION_PORTRAIT:
// swap values because preview sizes are always landscape
textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth(), relativeDisplayRotation);
break;
case Configuration.ORIENTATION_LANDSCAPE:
textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight(), relativeDisplayRotation);
break;
}
// working more memory efficient
SurfaceTexture surface = textureView.getSurfaceTexture();
if (surface != null) {
surface.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
} else {
throw new CameraException("surface texture not attached to view");
}
}
示例12: selectPreviewSize
import android.util.Size; //導入依賴的package包/類
/**
* Chooses an appropriate size for the images within the preview stream.
*
* @param camera camera to get available preview sizes
* @return the preview size to use
* @throws CameraException if the preview size could not be determined
*/
@NonNull
public Size selectPreviewSize(@NonNull CameraDevice camera) {
Size[] previewSizes = cameraCharacteristicsHelper.getPreviewOutputSizes(camera.getId());
if (previewSizes == null || previewSizes.length == 0) {
throw new CameraException("camera did not provide any preview size");
}
// preferably the preview has a size of 640x480 to save bandwidth while being large enough for the backend to be acceptable
for (Size imageSize : previewSizes) {
if (imageSize.getWidth() == 640 && imageSize.getHeight() == 480) {
return imageSize;
}
}
// fallback to first one which might not be optimal
log.w("preferred preview size of 640x480 is not available, using %s", previewSizes[0]);
return previewSizes[0];
}
示例13: setUp
import android.util.Size; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
surfaces = asList(surface1, surface2);
when(manager.getCameraIdList()).thenReturn(new String[]{CAMERA_ID_1, CAMERA_ID_2});
when(characteristicsHelper.getLensFacing(CAMERA_ID_1)).thenReturn(CameraCharacteristics.LENS_FACING_BACK);
when(characteristicsHelper.getLensFacing(CAMERA_ID_2)).thenReturn(CameraCharacteristics.LENS_FACING_FRONT);
when(characteristicsHelper.getSensorOrientation(CAMERA_ID_1)).thenReturn(SENSOR_ROTATION);
when(characteristicsHelper.getPreviewOutputSizes(CAMERA_ID_1)).thenReturn(
new Size[]{PREVIEWSIZE_1, PREVIEWSIZE_640x480, PREVIEWSIZE_2});
when(camera.getId()).thenReturn(CAMERA_ID_1);
when(camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)).thenReturn(captureRequestBuilder);
when(textureView.getSurfaceTexture()).thenReturn(surfaceTexture);
}
示例14: chooseVideoSize
import android.util.Size; //導入依賴的package包/類
/**
* We choose a largest video size with mAspectRatio. Also, we don't use sizes
* larger than 1080p, since MediaRecorder cannot handle such a high-resolution video.
*
* @param choices The list of available sizes
* @return The video size
*/
Size chooseVideoSize(Size[] choices) {
List<Size> videoSizes = Arrays.asList(choices);
List<Size> supportedVideoSizes = new ArrayList<>();
Collections.sort(videoSizes, new CompareSizesByArea());
for (int i = videoSizes.size() - 1; i >= 0; i--) {
if (videoSizes.get(i).getWidth() <= MAX_PREVIEW_WIDTH &&
videoSizes.get(i).getHeight() <= MAX_PREVIEW_HEIGHT) {
supportedVideoSizes.add(videoSizes.get(i));
if (videoSizes.get(i).getWidth() == videoSizes.get(i).getHeight() *
mAspectRatio.getX() / mAspectRatio.getY()) {
return videoSizes.get(i);
}
}
}
return supportedVideoSizes.size() > 0 ? supportedVideoSizes.get(0) : choices[choices.length - 1];
}
示例15: chooseOptimalSize
import android.util.Size; //導入依賴的package包/類
/**
* Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
* is at least as large as the respective texture view size, and that is at most as large as the
* respective max size, and whose aspect ratio matches with the specified value. If such size
* doesn't exist, choose the largest one that is at most as large as the respective max size,
* and whose aspect ratio matches with the specified value.
*
* @param choices The list of sizes that the camera supports for the intended output
* class
* @param textureViewWidth The width of the texture view relative to sensor coordinate
* @param textureViewHeight The height of the texture view relative to sensor coordinate
* @param maxWidth The maximum width that can be chosen
* @param maxHeight The maximum height that can be chosen
* @param aspectRatio The aspect ratio
* @return The optimal {@code Size}, or an arbitrary one if none were big enough
*/
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth,
int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) {
// Collect the supported resolutions that are at least as big as the preview Surface
List<Size> bigEnough = new ArrayList<>();
// Collect the supported resolutions that are smaller than the preview Surface
List<Size> notBigEnough = new ArrayList<>();
int w = aspectRatio.getWidth();
int h = aspectRatio.getHeight();
for (Size option : choices) {
if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&
option.getHeight() == option.getWidth() * h / w) {
if (option.getWidth() >= textureViewWidth &&
option.getHeight() >= textureViewHeight) {
bigEnough.add(option);
} else {
notBigEnough.add(option);
}
}
}
// Pick the smallest of those big enough. If there is no one big enough, pick the
// largest of those not big enough.
if (bigEnough.size() > 0) {
return Collections.min(bigEnough, new CompareSizesByArea());
} else if (notBigEnough.size() > 0) {
return Collections.max(notBigEnough, new CompareSizesByArea());
} else {
Log.e(TAG, "Couldn't find any suitable preview size");
return choices[0];
}
}