RoundedIconGenerator.java 文件源码

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

项目:chromium-for-android-56-debug-video 作者:
/**
 * Generates an icon based on |text|.
 *
 * @param text The text to render the first character of on the icon.
 * @return The generated icon.
 */
public Bitmap generateIconForText(String text) {
    Bitmap icon = Bitmap.createBitmap(mIconWidthPx, mIconHeightPx, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(icon);

    canvas.drawRoundRect(mBackgroundRect, mCornerRadiusPx, mCornerRadiusPx, mBackgroundPaint);

    String displayText = text.substring(0, 1).toUpperCase(Locale.getDefault());
    float textWidth = mTextPaint.measureText(displayText);

    canvas.drawText(
            displayText,
            (mIconWidthPx - textWidth) / 2f,
            Math.round((Math.max(mIconHeightPx, mTextHeight) - mTextHeight)
                    / 2.0f + mTextYOffset),
            mTextPaint);

    return icon;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号