图片内加字

    /**
     * 图片内加字
     */
    public static Bitmap addWordToPicture(Context context, int resourcesId, String content, int testSize, @ColorInt int color) {
        Drawable mCounterDrawable = null;
        Paint mPaint = null;
        if (mCounterDrawable == null) {
            mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            mCounterDrawable = context.getResources().getDrawable(resourcesId);
            mPaint.setTextAlign(Paint.Align.CENTER);
            mPaint.setTypeface(Typeface.DEFAULT_BOLD);
            mPaint.setColor(color);
            mPaint.setTextSize(Utils.sp2px(context, testSize));
        }
        Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
        Bitmap bitmapDrawable = ((BitmapDrawable) mCounterDrawable).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
        int bitmapX = bitmapDrawable.getWidth();
        int bitmapY = bitmapDrawable.getHeight();
        Canvas canvas = new Canvas(bitmapDrawable);
        canvas.drawText(content, bitmapX / 2, bitmapY / 2 + (fontMetrics.bottom - fontMetrics.top) / 4,
                mPaint);
        canvas.save();
        return bitmapDrawable;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值