IconNormalizer.java 文件源码

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

项目:LaunchEnr 作者:
/**
 * Returns if the shape of the icon is same as the path.
 * For this method to work, the shape path bounds should be in [0,1]x[0,1] bounds.
 */
private boolean isShape(Path maskPath) {
    // Condition1:
    // If width and height of the path not close to a square, then the icon shape is
    // not same as the mask shape.
    float iconRatio = ((float) mBounds.width()) / mBounds.height();
    if (Math.abs(iconRatio - 1) > BOUND_RATIO_MARGIN) {
        return false;
    }

    // Condition 2:
    // Actual icon (white) and the fitted shape (e.g., circle)(red) XOR operation
    // should generate transparent image, if the actual icon is equivalent to the shape.
    mFileId = mRandom.nextInt();
    mBitmapARGB.eraseColor(Color.TRANSPARENT);
    mCanvasARGB.drawBitmap(mBitmap, 0, 0, mPaintIcon);

    // Fit the shape within the icon's bounding box
    mMatrix.reset();
    mMatrix.setScale(mBounds.width(), mBounds.height());
    mMatrix.postTranslate(mBounds.left, mBounds.top);
    maskPath.transform(mMatrix);

    // XOR operation
    mCanvasARGB.drawPath(maskPath, mPaintMaskShape);

    // DST_OUT operation around the mask path outline
    mCanvasARGB.drawPath(maskPath, mPaintMaskShapeOutline);

    boolean isTrans = isTransparentBitmap(mBitmapARGB);

    // Check if the result is almost transparent
    if (!isTrans) {
        return false;
    }
    return true;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号