CropImageView.java 文件源码

java
阅读 38 收藏 0 点赞 0 评论 0

项目:SuperSelector 作者:
private void adjustRatio() {
    if (mImageRect == null) return;
    float imgW = mImageRect.right - mImageRect.left;
    float imgH = mImageRect.bottom - mImageRect.top;
    float frameW = getRatioX(imgW);
    float frameH = getRatioY(imgH);
    float imgRatio = imgW / imgH;
    float frameRatio = frameW / frameH;
    float l = mImageRect.left, t = mImageRect.top, r = mImageRect.right, b = mImageRect.bottom;
    if (frameRatio >= imgRatio) {
        l = mImageRect.left;
        r = mImageRect.right;
        float hy = (mImageRect.top + mImageRect.bottom) * 0.5f;
        float hh = (imgW / frameRatio) * 0.5f;
        t = hy - hh;
        b = hy + hh;
    } else if (frameRatio < imgRatio) {
        t = mImageRect.top;
        b = mImageRect.bottom;
        float hx = (mImageRect.left + mImageRect.right) * 0.5f;
        float hw = imgH * frameRatio * 0.5f;
        l = hx - hw;
        r = hx + hw;
    }
    float w = r - l;
    float h = b - t;
    float cx = l + w / 2;
    float cy = t + h / 2;
    float sw = w * mInitialFrameScale;
    float sh = h * mInitialFrameScale;
    mFrameRect = new RectF(cx - sw / 2, cy - sh / 2, cx + sw / 2, cy + sh / 2);
    invalidate();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号