// --参数计算--------------------------------------------------------------- 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); }
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); } }
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); } }
public float getZoomY() { mZoom = adjustZoom(mZoom); return Math.min(mZoom, mZoom / mAspectQuotient) * mView.getHeight() / mBitmap.getHeight(); }