Exemple #1
0
  /**
   * 根据ImageView获得适当的压缩的宽和高
   *
   * @param imageView
   * @return
   */
  private ImageSize getImageViewSize(ImageView imageView) throws Exception {
    ImageSize imageSize = new ImageSize();

    ViewGroup.LayoutParams lp = imageView.getLayoutParams();
    DisplayMetrics dm = imageView.getContext().getResources().getDisplayMetrics();

    int width = imageView.getWidth();

    if (width <= 0) {
      width = lp.width;
    }

    if (width <= 0) {
      width = getImagViewFieldValue(imageView, "mMaxWidth");
    }

    if (width <= 0) {
      width = dm.widthPixels;
    }

    int height = imageView.getHeight();

    if (height <= 0) {
      height = lp.height;
    }

    if (height <= 0) {
      height = getImagViewFieldValue(imageView, "mMaxHeight"); // 检查最大值
    }

    if (height <= 0) {
      height = dm.heightPixels;
    }

    imageSize.width = width;
    imageSize.height = height;

    return imageSize;
  }