Exemplo n.º 1
0
  // --参数计算---------------------------------------------------------------
  public void resetZoomState(ImageZoomView view, Bitmap bitmap) {
    mView = view;
    mBitmap = bitmap;
    mAspectQuotient = -1;

    do {
      if (null == mView || null == mBitmap) {
        break;
      }

      if (mView.getHeight() <= 0
          || mView.getWidth() <= 0
          || mBitmap.getHeight() <= 0
          || mBitmap.getWidth() <= 0) {
        break;
      }

      mAspectQuotient =
          (((float) mBitmap.getWidth()) / mBitmap.getHeight())
              / (((float) mView.getWidth()) / mView.getHeight());

      logd("mAspectQuotient = " + mAspectQuotient);
      calculateMinMaxZoom();
      calculateMinMaxPanX();
      calculateMinMaxPanY();

      // 初始化OK,通知外部,显示小图标
      setZoomChanged();
      notifyObservers();
    } while (false);
  }
Exemplo n.º 2
0
 @Override
 public void handleMessage(Message msg) {
   progressBar.setVisibility(View.GONE);
   mZoomView.setImage(mBitmap);
   mZoomState = new ZoomState();
   mZoomView.setZoomState(mZoomState);
   mZoomListener = new SimpleZoomListener();
   mZoomListener.setZoomState(mZoomState);
   mZoomView.setOnTouchListener(mZoomListener);
   resetZoomState();
 }
Exemplo n.º 3
0
  public float toImageY(float screenY) {
    float imageY = -1;

    mView.calculateRect();
    Rect mRectSrc = mView.getSrcRect();
    Rect mRectDst = mView.getDstRect();

    do {
      if (screenY < mRectDst.top || screenY > mRectDst.bottom) {
        break;
      }
      imageY = (screenY - mRectDst.top) / getZoomY() + mRectSrc.top;
    } while (false);

    // logd("toImageY " + screenY + " -> " + imageY);

    return imageY;
  }
Exemplo n.º 4
0
  /** 图片坐标转为屏幕坐标 返回 屏幕坐标,当screenX或screenY超出图片范围时,返回值 < 0 */
  public float toImageX(float screenX) {
    float imageX = -1;

    mView.calculateRect();
    Rect mRectSrc = mView.getSrcRect();
    Rect mRectDst = mView.getDstRect();

    do {
      if (screenX < mRectDst.left || screenX > mRectDst.right) {
        break;
      }
      imageX = (screenX - mRectDst.left) / getZoomX() + mRectSrc.left;
    } while (false);

    // logd("toImageX " + screenX + " -> " + imageX);

    return imageX;
  }
Exemplo n.º 5
0
  public float toScreenY(float imageY) {
    float screenY = -1;

    mView.calculateRect();
    Rect mRectSrc = mView.getSrcRect();
    Rect mRectDst = mView.getDstRect();

    do {
      if (imageY < 0 || imageY > mBitmap.getHeight()) {
        break;
      }
      screenY = (imageY - mRectSrc.top) * getZoomY() + mRectDst.top;
    } while (false);

    // logd("toScreenY " + imageY + " -> " + screenY);

    return screenY;
  }
Exemplo n.º 6
0
  /** 图片坐标转为屏幕坐标 返回 屏幕坐标,当imageX或imageY超出图片范围时,返回值 < 0 */
  public float toScreenX(float imageX) {
    float screenX = -1;

    // 先计算一次,避免下面引用区域时不正确
    mView.calculateRect();
    Rect mRectSrc = mView.getSrcRect();
    Rect mRectDst = mView.getDstRect();

    do {
      // 是否超出图片范围
      if (imageX < 0 || imageX > mBitmap.getWidth()) {
        break;
      }
      // 转换
      screenX = (imageX - mRectSrc.left) * getZoomX() + mRectDst.left;
    } while (false);

    // logd("toScreenX " + imageX + " -> " + screenX);

    return screenX;
  }
Exemplo n.º 7
0
  private void calculateMinMaxZoom() {
    if (mAspectQuotient > 0) {
      float bmpW = mBitmap.getWidth();
      float viewW = mView.getWidth();
      float bmpH = mBitmap.getHeight();
      float viewH = mView.getHeight();

      if (mAspectQuotient > 1) {
        mStdMinZoom = 1;
        mMidZoom = mAspectQuotient;
        mStdMaxZoom = bmpW / viewW;
      } else {
        mStdMinZoom = 1;
        mMidZoom = 1 / mAspectQuotient;
        mStdMaxZoom = bmpH / viewH;
      }
      mZoom = mStdMinZoom;
      mMinZoom = mStdMinZoom * (1 - 0.35f);
      mMaxZoom = mStdMaxZoom * (1 + 0.2f);
      logd("mStdMinZoom,mStdMaxZoom =" + mStdMinZoom + "," + mStdMaxZoom);
      logd("mMinZoom,mMidZoom,mMaxZoom =" + mMinZoom + "," + mMidZoom + "," + mMaxZoom);
    }
  }
Exemplo n.º 8
0
  private void calculateMinMaxPanY() {
    if (mAspectQuotient > 0) {
      float bmpH = mBitmap.getHeight();
      float viewH = mView.getHeight();

      float zoomY = getZoomY();
      mStdMinPanY = viewH / (zoomY * 2 * bmpH);
      mStdMaxPanY = 1 - mStdMinPanY;
      if (mAspectQuotient > 1) {
        if (mZoom <= mMidZoom) { // 上下两边出现空隙时,居中显示
          mStdMinPanY = mStdMaxPanY = 0.5f;
        }
      } else {
        if (mZoom <= mStdMinZoom) {
          mStdMinPanY = mStdMaxPanY = 0.5f;
        }
      }
      mMinPanY = (viewH / 2 + 10) / (zoomY * 2 * bmpH);
      mMaxPanY = 1 - mMinPanY;
      logd("mStdMinPanY,mStdMaxPanY =" + mStdMinPanY + "," + mStdMaxPanY);
      logd("mMinPanY,mMaxPanY =" + mMinPanY + "," + mMaxPanY);
    }
  }
Exemplo n.º 9
0
  private void calculateMinMaxPanX() {
    if (mAspectQuotient > 0) {
      float bmpW = mBitmap.getWidth();
      float viewW = mView.getWidth();

      float zoomX = getZoomX();
      mStdMinPanX = viewW / (zoomX * 2 * bmpW);
      mStdMaxPanX = 1 - mStdMinPanX;
      if (mAspectQuotient <= 1) {
        if (mZoom <= mMidZoom) { // 左右两边出现空隙时,居中显示
          mStdMinPanX = mStdMaxPanX = 0.5f;
        }
      } else {
        if (mZoom <= mStdMinZoom) {
          mStdMinPanX = mStdMaxPanX = 0.5f;
        }
      }
      mMinPanX = (viewW / 2 + 10) / (zoomX * 2 * bmpW);
      mMaxPanX = 1 - mMinPanX;
      // logd("mStdMinPanX,mStdMaxPanX =" + mStdMinPanX + "," + mStdMaxPanX);
      // logd("mMinPanX,mMaxPanX =" + mMinPanX + "," + mMaxPanX);
    }
  }
Exemplo n.º 10
0
 public float getZoomY() {
   mZoom = adjustZoom(mZoom);
   return Math.min(mZoom, mZoom / mAspectQuotient) * mView.getHeight() / mBitmap.getHeight();
 }
Exemplo n.º 11
0
 public float getZoomX() {
   mZoom = adjustZoom(mZoom);
   return Math.min(mZoom, mZoom * mAspectQuotient) * mView.getWidth() / mBitmap.getWidth();
 }
Exemplo n.º 12
0
 public void setPoints(ArrayList<Float> mXs, ArrayList<Float> mYs) {
   mView.setPoints(mXs, mYs);
 }