Code example for Rect

Methods: heightwidth

0
    if (framingRectInPreview == null) {
      Rect framingRect = getFramingRect();
      if (framingRect == null) {
        return null; 
      } 
      Rect rect = new Rect(framingRect);
      Point cameraResolution = configManager.getCameraResolution();
      Point screenResolution = configManager.getScreenResolution();
      if (cameraResolution == null || screenResolution == null) {
        // Called early, before init even finished 
        return null; 
      } 
      rect.left = rect.left * cameraResolution.x / screenResolution.x;
      rect.right = rect.right * cameraResolution.x / screenResolution.x;
      rect.top = rect.top * cameraResolution.y / screenResolution.y;
      rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
      framingRectInPreview = rect;
    } 
    return framingRectInPreview;
  } 
 
  /** 
   * Allows third party apps to specify the scanning rectangle dimensions, rather than determine 
   * them automatically based on screen resolution. 
   * 
   * @param width The width in pixels to scan. 
   * @param height The height in pixels to scan. 
   */ 
  public synchronized void setManualFramingRect(int width, int height) {
    if (initialized) {
      Point screenResolution = configManager.getScreenResolution();
      if (width > screenResolution.x) {
        width = screenResolution.x;
      } 
      if (height > screenResolution.y) {
        height = screenResolution.y;
      } 
      int leftOffset = (screenResolution.x - width) / 2;
      int topOffset = (screenResolution.y - height) / 2;
      framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
      Log.d(TAG, "Calculated manual framing rect: " + framingRect);
      framingRectInPreview = null;
    } else { 
      requestedFramingRectWidth = width;
      requestedFramingRectHeight = height;
    } 
  } 
 
  /** 
   * A factory method to build the appropriate LuminanceSource object based on the format 
   * of the preview buffers, as described by Camera.Parameters. 
   * 
   * @param data A preview frame. 
   * @param width The width of the image. 
   * @param height The height of the image. 
   * @return A PlanarYUVLuminanceSource instance. 
   */ 
  public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    if (rect == null) {
      return null; 
    } 
    // Go ahead and assume it's YUV rather than die. 
    return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                                        rect.width(), rect.height(), false);
  } 
 
} 
Connect your IDE to all the code out there  Get Codota for Java