android.util.Size类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中android.util.Size类的一些代码示例,展示了Size类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Size类的具体详情如下:
包路径:android.util.Size
类名称:Size

Size介绍

[英]Created by rharter on 10/29/15.
[中]由rharter于2015年10月29日创作。

代码示例

代码示例来源:origin: googlesamples/android-Camera2Basic

@Override
public int compare(Size lhs, Size rhs) {
  // We cast here to ensure the multiplications won't overflow
  return Long.signum((long) lhs.getWidth() * lhs.getHeight() -
      (long) rhs.getWidth() * rhs.getHeight());
}

代码示例来源:origin: ArkadyGamza/Camera2API_rxJava2

/**
 * Sensor could be rotated in the device, this method returns normal orientation sensor dimension
 */
public static Size getSensorSizeRotated(@NonNull CameraCharacteristics characteristics, @NonNull Size sensorSize) {
  int sensorOrientationDegrees = CameraOrientationHelper.getSensorOrientation(characteristics);
  if (sensorOrientationDegrees % 180 == 0) {
    return sensorSize;
  }
  // swap dimensions
  return new Size(sensorSize.getHeight(), sensorSize.getWidth());
}

代码示例来源:origin: MasayukiSuda/GPUVideo-android

public GPUMp4Composer size(int width, int height) {
  this.outputResolution = new Size(width, height);
  return this;
}

代码示例来源:origin: MasayukiSuda/GPUVideo-android

@Override
  public void onStart(Size previewSize, boolean flash) {
    Log.d(TAG, "previewSize : width " + previewSize.getWidth() + " height = " + previewSize.getHeight());
    if (glPreviewRenderer != null) {
      glPreviewRenderer.setCameraResolution(new Size(previewSize.getWidth(), previewSize.getHeight()));
    }
    flashSupport = flash;
    if (cameraRecordListener != null) {
      cameraRecordListener.onGetFlashSupport(flashSupport);
    }
    final float previewWidth = previewSize.getWidth();
    final float previewHeight = previewSize.getHeight();
    glSurfaceView.post(new Runnable() {
      @Override
      public void run() {
        if (glPreviewRenderer != null) {
          glPreviewRenderer.setAngle(degrees);
          glPreviewRenderer.onStartPreview(previewWidth, previewHeight, isLandscapeDevice);
        }
      }
    });
    if (glPreviewRenderer != null) {
      final SurfaceTexture st = glPreviewRenderer.getPreviewTexture().getSurfaceTexture();
      st.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
    }
  }
}, surfaceTexture, cameraManager, lensFacing);

代码示例来源:origin: google-ar/sceneform-android-sdk

public void setVideoSize(int width, int height) {
 videoSize = new Size(width, height);
}

代码示例来源:origin: florent37/CameraFragment

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Size(android.util.Size size) {
  this.width = size.getWidth();
  this.height = size.getHeight();
}

代码示例来源:origin: Nilhcem/tensorflow-classifier-android

@Override
public void onSurfaceTextureAvailable(
  final SurfaceTexture texture, final int width, final int height) {
 int index = getCameraId();
 camera = Camera.open(index);
 try {
  Camera.Parameters parameters = camera.getParameters();
  parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
  List<Camera.Size> cameraSizes = parameters.getSupportedPreviewSizes();
  Size[] sizes = new Size[cameraSizes.size()];
  int i = 0;
  for (Camera.Size size : cameraSizes) {
   sizes[i++] = new Size(size.width, size.height);
  }
  Size previewSize =
    CameraConnectionFragment.chooseOptimalSize(
      sizes, desiredSize.getWidth(), desiredSize.getHeight());
  parameters.setPreviewSize(previewSize.getWidth(), previewSize.getHeight());
  camera.setDisplayOrientation(90);
  camera.setParameters(parameters);
  camera.setPreviewTexture(texture);
 } catch (IOException exception) {
  camera.release();
 }
 camera.setPreviewCallbackWithBuffer(imageListener);
 Camera.Size s = camera.getParameters().getPreviewSize();
 camera.addCallbackBuffer(new byte[ImageUtils.getYUVByteSize(s.height, s.width)]);
 textureView.setAspectRatio(s.height, s.width);
 camera.startPreview();
}

代码示例来源:origin: yangjie10930/OpenGL4Android

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
  Log.v("MP4Sur", "++onSurfaceTextureSizeChanged++");
  mPreSize = new Size(width, height);
  mp4Edior.setOutputSurface(mSurface, width, height);
}

代码示例来源:origin: square/picasso

@Override
 public void onHeaderDecoded(@NonNull ImageDecoder imageDecoder,
   @NonNull ImageDecoder.ImageInfo imageInfo, @NonNull ImageDecoder.Source source) {
  if (request.hasSize()) {
   Size size = imageInfo.getSize();
   if (shouldResize(request.onlyScaleDown, size.getWidth(), size.getHeight(),
     request.targetWidth, request.targetHeight)) {
    imageDecoder.setTargetSize(request.targetWidth, request.targetHeight);
   }
  }
 }
});

代码示例来源:origin: 18Gray/ProCamera

@Override
public void configureCamera(int width, int height, int cameraNum)
{
  try
  {
    mCameraId = manager.getCameraIdList()[cameraNum];
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
    //设置输出选项
    StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
    mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize);
    mPreviewSize = new Size(getMeasuredWidth(), getMeasuredHeight());
    //如果屏幕旋转需要调整
    int orientation = getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
      setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());
    } else
    {
      setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());
    }
  } catch (CameraAccessException e)
  {
  }
}

代码示例来源:origin: yangjie10930/OpenGL4Android

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
  mPreSize = new Size(width, height);
  mp4Edior.setOutputSurface(mSurface, width, height);
}

代码示例来源:origin: vondear/RxTool

protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
  for (android.util.Size size : map.getOutputSizes(ImageFormat.JPEG)) {
    mPictureSizes.add(new Size(size.getWidth(), size.getHeight()));
  }
}

代码示例来源:origin: MasayukiSuda/GPUVideo-android

@Override
public void setFrameSize(int width, int height) {
  super.setFrameSize(width, height);
  setResolution(new Size(width, height));
}

代码示例来源:origin: google/cameraview

protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
  for (android.util.Size size : map.getOutputSizes(ImageFormat.JPEG)) {
    mPictureSizes.add(new Size(size.getWidth(), size.getHeight()));
  }
}

代码示例来源:origin: MasayukiSuda/CameraRecorder-android

@Override
public void setFrameSize(int width, int height) {
  super.setFrameSize(width, height);
  setResolution(new Size(width, height));
}

代码示例来源:origin: googlesamples/android-Camera2Basic

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 {

代码示例来源:origin: yangjie10930/OpenGL4Android

@Override
      public void surfaceCreated(SurfaceHolder holder) { //SurfaceView创建
//                initCamera2();
        // 初始化Camera
        mCameraRecord.setOutputSurface(holder.getSurface());
        mCameraRecord.setOutputSize(new Size(768, 1080));
        mCameraRecord.setRenderer(Camera2Activity.this);
      }

代码示例来源:origin: googlesamples/android-Camera2Basic

Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
  matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
  float scale = Math.max(
      (float) viewHeight / mPreviewSize.getHeight(),
      (float) viewWidth / mPreviewSize.getWidth());
  matrix.postScale(scale, scale, centerX, centerY);
  matrix.postRotate(90 * (rotation - 2), centerX, centerY);

代码示例来源:origin: MasayukiSuda/GPUVideo-android

private Size getVideoResolution(final String path, final int rotation) {
  MediaMetadataRetriever retriever = null;
  try {
    retriever = new MediaMetadataRetriever();
    retriever.setDataSource(path);
    int width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
    int height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
    return new Size(width, height);
  } finally {
    try {
      if (retriever != null) {
        retriever.release();
      }
    } catch (RuntimeException e) {
      Log.e(TAG, "Failed to release mediaMetadataRetriever.", e);
    }
  }
}

代码示例来源:origin: vondear/RxTool

@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);
  }
}

相关文章