/**
* 图片内加字
*/
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;
}
图片内加字
猜你喜欢
转载自blog.csdn.net/DengDongQi/article/details/80880435
今日推荐
周排行