android.hardware.Camera.Size Java Examples

The following examples show how to use android.hardware.Camera.Size. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CameraWrapper.java    From VideoCamera with Apache License 2.0 6 votes vote down vote up
@TargetApi(VERSION_CODES.HONEYCOMB)
protected List<Size> getSupportedVideoSizes(int currentSdkInt) {
    Parameters params = mNativeCamera.getNativeCameraParameters();

    List<Size> supportedVideoSizes;
    if (currentSdkInt < Build.VERSION_CODES.HONEYCOMB) {
        CLog.e(CLog.CAMERA, "Using supportedPreviewSizes iso supportedVideoSizes due to API restriction");
        supportedVideoSizes = params.getSupportedPreviewSizes();
    } else if (params.getSupportedVideoSizes() == null) {
        CLog.e(CLog.CAMERA, "Using supportedPreviewSizes because supportedVideoSizes is null");
        supportedVideoSizes = params.getSupportedPreviewSizes();
    } else {
        supportedVideoSizes = params.getSupportedVideoSizes();
    }

    return supportedVideoSizes;
}
 
Example #2
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 6 votes vote down vote up
public void setMaxPreviewResolution() {
    int maxWidth=0;
    Size curRes=null;

    mCamera.lock();

    for ( Size r: getResolutionList() ) {
        if (r.width>maxWidth) {
            Log.d(TAG,"supported preview resolution: "+r.width+"x"+r.height);
            maxWidth=r.width;
            curRes=r;
        }
    }

    if (curRes!=null) {
        setResolution(curRes);
        Log.d(TAG, "selected preview resolution: " + curRes.width + "x" + curRes.height);
    }

    return;
}
 
Example #3
Source File: MainActivity.java    From Form-N-Fun with MIT License 6 votes vote down vote up
@Override
public void onCameraViewStarted(int width, int height) {

    String caption = Integer.valueOf(mOpenCvCameraView.getWidth()).toString() + "x" + Integer.valueOf(mOpenCvCameraView.getHeight()).toString();
    Log.v("screen_size ",caption);
    List<Camera.Size> mResolutionList = mOpenCvCameraView.getResolutionList();
    Camera.Size mSize = null;
    for (Camera.Size size : mResolutionList) {
        Log.i(TAG, "Available resolution: "+size.width+" "+size.height);
        if(size.width<=1280&&size.height<=960) { //change the resolution, 1280x960 and 1440x1080 are working fine in nexus 5x
            mSize = size;
            Log.i(TAG, "selected resolution: "+size.width+" "+size.height);
            break;
        }
    }
    mOpenCvCameraView.setResolution(mSize); //set resolution
    Size resolution = mOpenCvCameraView.getResolution();
    mRgba = new Mat();
    //initialize findmazesandballs
    findmazesandballs = new FindMazesAndBalls(mOpenCvCameraView.getWidth(), mOpenCvCameraView.getHeight(),resolution.width, resolution.height);
    if(findmazesandballs.getselfAddr()!=0&&gs != null)
        gs.setAddressandScreenSize(findmazesandballs.getselfAddr(),mOpenCvCameraView.getWidth(),mOpenCvCameraView.getHeight());
}
 
Example #4
Source File: CameraEngine.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo   getCameraInfo(){
    com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo  info = new com.tiktokdemo.lky.tiktokdemo.record.camera.camera.utils.CameraInfo();

    try{
    Size size = getPreviewSize();
    CameraInfo cameraInfo = new CameraInfo();
    mCameraInfo = cameraInfo;
        Camera.getCameraInfo(cameraID, cameraInfo);
    info.previewWidth = PREVIEW_WIDTH;
    info.previewHeight = PREVIEW_HEIGHT;
    info.orientation = cameraInfo.orientation;
    info.isFront = cameraID == 1 ? true : false;
    size = getPictureSize();
    if (size != null){
        info.pictureWidth = size.width;
        info.pictureHeight = size.height;
    }
    if(camera != null){
        info.flashMode = camera.getParameters().getFlashMode();
    }
    return info;
    }catch (Exception e){
        e.printStackTrace();
        return info;
    }
}
 
Example #5
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 6 votes vote down vote up
public Camera.Size getMaxPreviewResolution() {
    int maxWidth=0;
    Camera.Size curRes=null;

    mCamera.lock();

    for ( Camera.Size r: getResolutionList() ) {
        if (r.width>maxWidth) {
            Log.d(TAG,"supported preview resolution: "+r.width+"x"+r.height);
            maxWidth=r.width;
            curRes=r;
        }
    }

    return curRes;
}
 
Example #6
Source File: GPUImageRenderer.java    From SimpleVideoEditor with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
    final Size previewSize = camera.getParameters().getPreviewSize();
    if (mGLRgbBuffer == null) {
        mGLRgbBuffer = IntBuffer.allocate(previewSize.width * previewSize.height);
    }
    if (mRunOnDraw.isEmpty()) {
        runOnDraw(new Runnable() {
            @Override
            public void run() {
                GPUImageNativeLibrary.YUVtoRBGA(data, previewSize.width, previewSize.height,
                        mGLRgbBuffer.array());
                mGLTextureId = OpenGlUtils.loadTexture(mGLRgbBuffer, previewSize, mGLTextureId);
                camera.addCallbackBuffer(data);

                if (mImageWidth != previewSize.width) {
                    mImageWidth = previewSize.width;
                    mImageHeight = previewSize.height;
                    adjustImageScaling();
                }
            }
        });
    }
}
 
Example #7
Source File: CameraView.java    From zom-android-matrix with Apache License 2.0 6 votes vote down vote up
private void startPreview(SurfaceHolder holder) {
	try {

		Parameters params = camera.getParameters();

		if (params.getSupportedFocusModes().contains(
				Parameters.FOCUS_MODE_AUTO)) {
			params.setFocusMode(Parameters.FOCUS_MODE_AUTO);
		}

		List<Size> previewSizes = camera.getParameters().getSupportedPreviewSizes();
		List<Size> pictureSizes = camera.getParameters().getSupportedPictureSizes();

           params.setPreviewSize(previewSizes.get(previewSizes.size()-2).width,previewSizes.get(previewSizes.size()-2).height);
		params.setPictureSize(pictureSizes.get(pictureSizes.size()-2).width,pictureSizes.get(pictureSizes.size()-2).height);
		camera.setParameters(params);

		camera.setPreviewDisplay(holder);
		camera.startPreview();

		previewConsumer.start(camera);
	} catch(IOException e) {
		Log.e(TAG, "Error starting camera preview", e);
	}
}
 
Example #8
Source File: OpenGlUtils.java    From SimpleVideoEditor with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example #9
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 6 votes vote down vote up
public void setMaxPictureResolution() {
    int maxWidth=0;
    Size curRes=null;
    for ( Size r: getPictureResolutionList() ) {
        Log.d(TAG,"supported picture resolution: "+r.width+"x"+r.height);
        if (r.width>maxWidth) {
            maxWidth=r.width;
            curRes=r;
        }
    }

    if (curRes!=null) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setPictureSize(curRes.width, curRes.height);
        mCamera.setParameters(parameters);
        Log.d(TAG, "selected picture resolution: " + curRes.width + "x" + curRes.height);
    }

    return;
}
 
Example #10
Source File: CameraView.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private Rect getCroppedRect(Size cameraPreviewSize, Rect visibleRect, int rotation) {
  final int previewWidth  = cameraPreviewSize.width;
  final int previewHeight = cameraPreviewSize.height;

  if (rotation % 180 > 0) rotateRect(visibleRect);

  float scale = (float) previewWidth / visibleRect.width();
  if (visibleRect.height() * scale > previewHeight) {
    scale = (float) previewHeight / visibleRect.height();
  }
  final float newWidth  = visibleRect.width()  * scale;
  final float newHeight = visibleRect.height() * scale;
  final float centerX   = (VERSION.SDK_INT < 14 || isTroublemaker()) ? previewWidth - newWidth / 2 : previewWidth / 2;
  final float centerY   = previewHeight / 2;

  visibleRect.set((int) (centerX - newWidth  / 2),
                  (int) (centerY - newHeight / 2),
                  (int) (centerX + newWidth  / 2),
                  (int) (centerY + newHeight / 2));

  if (rotation % 180 > 0) rotateRect(visibleRect);
  return visibleRect;
}
 
Example #11
Source File: MediaRecorderBase.java    From VideoRecord with MIT License 6 votes vote down vote up
/** 设置回调 */
protected void setPreviewCallback() {
	Camera.Size size = mParameters.getPreviewSize();
	if (size != null) {
		PixelFormat pf = new PixelFormat();
		PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
		int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
		try {
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.addCallbackBuffer(new byte[buffSize]);
			camera.setPreviewCallbackWithBuffer(this);
		} catch (OutOfMemoryError e) {
			Log.e("Yixia", "startPreview...setPreviewCallback...", e);
		}
		Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
	} else {
		camera.setPreviewCallback(this);
	}
}
 
Example #12
Source File: Utils.java    From code-scanner with MIT License 6 votes vote down vote up
@NonNull
public static Point findSuitableImageSize(@NonNull final Parameters parameters,
        final int frameWidth, final int frameHeight) {
    final List<Size> sizes = parameters.getSupportedPreviewSizes();
    if (sizes != null && !sizes.isEmpty()) {
        Collections.sort(sizes, new CameraSizeComparator());
        final float frameRatio = (float) frameWidth / (float) frameHeight;
        for (float distortion = MIN_DISTORTION; distortion <= MAX_DISTORTION;
                distortion += DISTORTION_STEP) {
            for (final Size size : sizes) {
                final int width = size.width;
                final int height = size.height;
                if (width * height >= MIN_PREVIEW_PIXELS &&
                        Math.abs(frameRatio - (float) width / (float) height) <= distortion) {
                    return new Point(width, height);
                }
            }
        }
    }
    final Size defaultSize = parameters.getPreviewSize();
    if (defaultSize == null) {
        throw new CodeScannerException("Unable to configure camera preview size");
    }
    return new Point(defaultSize.width, defaultSize.height);
}
 
Example #13
Source File: CameraUtil.java    From TextOcrExample with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有支持的预览尺寸
 */
public Size getPropPreviewSize(List<Size> list, int minWidth) {
    Collections.sort(list, ascendSizeComparator);

    int i = 0;
    for (Size s : list) {
        if ((s.width >= minWidth)) {
            break;
        }
        i++;
    }
    if (i == list.size()) {
        i = 0;//如果没找到,就选最小的size
    }
    return list.get(i);
}
 
Example #14
Source File: CameraView.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private Rect getCroppedRect(Size cameraPreviewSize, Rect visibleRect, int rotation) {
  final int previewWidth  = cameraPreviewSize.width;
  final int previewHeight = cameraPreviewSize.height;

  if (rotation % 180 > 0) rotateRect(visibleRect);

  float scale = (float) previewWidth / visibleRect.width();
  if (visibleRect.height() * scale > previewHeight) {
    scale = (float) previewHeight / visibleRect.height();
  }
  final float newWidth  = visibleRect.width()  * scale;
  final float newHeight = visibleRect.height() * scale;
  final float centerX   = (VERSION.SDK_INT < 14 || isTroublemaker()) ? previewWidth - newWidth / 2 : previewWidth / 2;
  final float centerY   = previewHeight / 2;

  visibleRect.set((int) (centerX - newWidth  / 2),
                  (int) (centerY - newHeight / 2),
                  (int) (centerX + newWidth  / 2),
                  (int) (centerY + newHeight / 2));

  if (rotation % 180 > 0) rotateRect(visibleRect);
  return visibleRect;
}
 
Example #15
Source File: CameraUtil.java    From TextOcrExample with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有支持的返回图片尺寸
 */
public Size getPropPictureSize(List<Size> list, int minWidth) {
    Collections.sort(list, ascendSizeComparator);

    int i = 0;
    for (Size s : list) {
        if ((s.width >= minWidth)) {
            break;
        }
        i++;
    }
    if (i == list.size()) {
        i = 0;//如果没找到,就选最小的size
    }
    return list.get(i);
}
 
Example #16
Source File: GLUtil.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example #17
Source File: VideoPusher.java    From LivePublisher with MIT License 5 votes vote down vote up
private void setPreviewSize(Camera.Parameters parameters) {
	List<Integer> supportedPreviewFormats = parameters
			.getSupportedPreviewFormats();
	for (Integer integer : supportedPreviewFormats) {
		System.out.println("支持:" + integer);
	}
	List<Size> supportedPreviewSizes = parameters
			.getSupportedPreviewSizes();
	Size size = supportedPreviewSizes.get(0);
	Log.d(TAG, "支持 " + size.width + "x" + size.height);
	int m = Math.abs(size.height * size.width - mParam.getHeight()
			* mParam.getWidth());
	supportedPreviewSizes.remove(0);
	Iterator<Size> iterator = supportedPreviewSizes.iterator();
	while (iterator.hasNext()) {
		Size next = iterator.next();
		Log.d(TAG, "支持 " + next.width + "x" + next.height);
		int n = Math.abs(next.height * next.width - mParam.getHeight()
				* mParam.getWidth());
		if (n < m) {
			m = n;
			size = next;
		}
	}
	mParam.setHeight(size.height);
	mParam.setWidth(size.width);
	parameters.setPreviewSize(mParam.getWidth(), mParam.getHeight());
	Log.d(TAG, "预览分辨率 width:" + size.width + " height:" + size.height);
}
 
Example #18
Source File: CameraWrapperTest.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
@Test
public void getSupportedVideoSizesGingerbread() {
    NativeCamera mockCamera = createCameraWithMockParameters(640, 480, 1280, 960);
    final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0);

    List<Size> supportedVideoSizes = wrapper.getSupportedVideoSizes(VERSION_CODES.GINGERBREAD);

    assertEquals(1280, supportedVideoSizes.get(0).width);
    assertEquals(960, supportedVideoSizes.get(0).height);
}
 
Example #19
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
public Camera.Size getMaxPictureResolution(float previewRatio) {
    int maxPixels=0;
    int ratioMaxPixels=0;
    Camera.Size currentMaxRes=null;
    Camera.Size ratioCurrentMaxRes=null;
    for ( Camera.Size r: getPictureResolutionList() ) {
        float pictureRatio = (float) r.width / r.height;
        Log.d(TAG,"supported picture resolution: "+r.width+"x"+r.height+" ratio: "+pictureRatio);
        int resolutionPixels = r.width * r.height;

        if (resolutionPixels>ratioMaxPixels && pictureRatio == previewRatio) {
            ratioMaxPixels=resolutionPixels;
            ratioCurrentMaxRes=r;
        }

        if (resolutionPixels>maxPixels) {
            maxPixels=resolutionPixels;
            currentMaxRes=r;
        }
    }

    //boolean matchAspect = mSharedPref.getBoolean("match_aspect", true);

    if (ratioCurrentMaxRes!=null && true) {

        Log.d(TAG,"Max supported picture resolution with preview aspect ratio: "
                + ratioCurrentMaxRes.width+"x"+ratioCurrentMaxRes.height);
        return ratioCurrentMaxRes;

    }

    return currentMaxRes;
}
 
Example #20
Source File: CameraManager.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
public Size getPreviewSize() {
	if (null != camera) {
		return camera.getParameters().getPreviewSize();

	}
	return null;
}
 
Example #21
Source File: Camera1Controller.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
public void setPictureSize(android.util.Size size) {
  Log.i(TAG, String.format("setting picture size (%d, %d)", size.getWidth(), size.getHeight()));
  assertNotState(STATE_NOT_ACQUIRED, "A camera must be acquired before setting parameters");
  Parameters params = camera.getParameters();
  params.setPictureSize(size.getWidth(), size.getHeight());
  camera.setParameters(params);
}
 
Example #22
Source File: SurfaceGrabberActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
protected Size choosePictureSize(List<Size> localSizes) {
    Size size = null;

    for (Size sz : localSizes) {
        if (sz.width > 640 && sz.width <= 1024)
            size = sz;

        if (size != null)
            break;
    }

    if (size == null)
        size = localSizes.get(localSizes.size() - 1);
    return size;
}
 
Example #23
Source File: CameraWrapperTest.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
private List<Camera.Size> createMockSize(int width, int height) {
    if (width <= 0 && height <= 0) {
        return null;
    }

    Size mockSize = mock(Size.class);
    mockSize.width = width;
    mockSize.height = height;

    List<Camera.Size> sizes = new ArrayList<>();
    sizes.add(mockSize);

    return sizes;
}
 
Example #24
Source File: CameraWrapperTest.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
@Test
public void returnPreviewSizeWhenVideoSizeIsNull() {
    NativeCamera mockCamera = createCameraWithMockParameters(0, 0, 1280, 960);
    final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0);

    List<Size> supportedVideoSizes = wrapper.getSupportedVideoSizes(VERSION_CODES.HONEYCOMB);

    assertEquals(1280, supportedVideoSizes.get(0).width);
    assertEquals(960, supportedVideoSizes.get(0).height);
}
 
Example #25
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
public void setResolution(Size resolution) {
    disconnectCamera();
    mMaxHeight = resolution.height;
    mMaxWidth = resolution.width;
    connectCamera(getWidth(), getHeight());
    Log.d(TAG,"resolution: "+resolution.width+" x "+resolution.height);
}
 
Example #26
Source File: MediaShootActivity.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public int compare(Size lhs, Size rhs) {
	if (lhs.width == rhs.width) {
		return 0;
	} else if (lhs.width > rhs.width) {
		return 1;
	} else {
		return -1;
	}
}
 
Example #27
Source File: CameraWrapperTest.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
@Test
public void getSupportedVideoSizesHoneyComb() {
    NativeCamera mockCamera = createCameraWithMockParameters(640, 480, 1280, 960);
    final CameraWrapper wrapper = new CameraWrapper(mockCamera, Surface.ROTATION_0);

    List<Size> supportedVideoSizes = wrapper.getSupportedVideoSizes(VERSION_CODES.HONEYCOMB);

    assertEquals(640, supportedVideoSizes.get(0).width);
    assertEquals(480, supportedVideoSizes.get(0).height);
}
 
Example #28
Source File: CameraUtils.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static @Nullable 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.d(TAG, String.format(Locale.US,
                           "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.d(TAG, String.format(Locale.US, "  %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.d(TAG, "    (ideal ratio)");
    } else if (size.width >= targetWidth && size.height >= targetHeight) {
      bigEnough.add(size);
      Log.d(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());
}
 
Example #29
Source File: CameraUtil.java    From TextOcrExample with Apache License 2.0 5 votes vote down vote up
public boolean equalRate(Size s, float rate) {
    float r = (float) (s.width) / (float) (s.height);
    if (Math.abs(r - rate) <= 0.03) {
        return true;
    } else {
        return false;
    }
}
 
Example #30
Source File: CameraUtil.java    From TextOcrExample with Apache License 2.0 5 votes vote down vote up
public int compare(Size lhs, Size rhs) {
    if (lhs.width == rhs.width) {
        return 0;
    } else if (lhs.width < rhs.width) {
        return 1;
    } else {
        return -1;
    }
}