Android 画文字图

画图

private Bitmap getbitmap(String content) {
Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);//创建一个宽度和高度都是400、32位ARGB图
Canvas canvas = new Canvas(bitmap);//初始化画布绘制的图像到icon上
canvas.drawColor(Color.WHITE);
/* Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//创建画笔
paint.setTextSize(50.0f);//设置文字的大小
paint.setTypeface(Typeface.DEFAULT_BOLD);//文字的样式(加粗)
paint.setColor(Color.GRAY);//文字的颜色
canvas.drawText(content, 10, 200, paint);//将文字写入。这里面的(120,130)代表着文字在图层上的初始位置
canvas.save(canvas.ALL_SAVE_FLAG);//保存所有图层
canvas.restore();*/

TextPaint textPaint = new TextPaint();
textPaint.setColor(Color.GRAY);
textPaint.setTextSize(50.0F);
StaticLayout layout = new StaticLayout(content,textPaint,400, Layout.Alignment.ALIGN_NORMAL,1.0F,0.0F,true);
canvas.save();
canvas.translate(10, 150);
layout.draw(canvas);
canvas.restore();

return bitmap;
}

转载于:https://www.cnblogs.com/guoke-jsp/p/5114119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值