DecodeBitmapTask.java 文件源码

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

项目:showroom-android 作者:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float pixels, int width, int height) {
    final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int sourceWidth = bitmap.getWidth();
    final int sourceHeight = bitmap.getHeight();

    float xScale = (float) width / bitmap.getWidth();
    float yScale = (float) height / bitmap.getHeight();
    float scale = Math.max(xScale, yScale);

    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    float left = (width - scaledWidth) / 2;
    float top = (height - scaledHeight) / 2;

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);

    final RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, pixels, pixels, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, null, targetRect, paint);

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


问题


面经


文章

微信
公众号

扫码关注公众号