Android bitmap绘制文字自动换行
public Bitmap getNewBitMap(String text) {
Bitmap newBitmap = Bitmap.createBitmap(,, Config.ARGB_4444);
Canvas canvas = new Canvas(newBitmap);
canvas.drawBitmap(bmp, , , null);
TextPaint textPaint = new TextPaint();
textPaint.setAntiAlias(true);
textPaint.setTextSize(16.0F);
StaticLayout sl= new StaticLayout(text, textPaint, newBitmap.getWidth()-, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
canvas.translate(, );
sl.draw(canvas);
return newBitmap;
}
Android StaticLayout参数解释
StaticLayout layout = new StaticLayout(context.getString(R.string.about),textPaint,(int)(300*fDensity),Alignment.ALIGN_CENTER,1.5F,0,false);
layout.draw(canvas);
参数含义:
1.字符串子资源
2 .画笔对象
3.layout的宽度,字符串超出宽度时自动换行。
4.layout的样式,有ALIGN_CENTER, ALIGN_NORMAL, ALIGN_OPPOSITE 三种。
5.相对行间距,相对字体大小,1.5f表示行间距为1.5倍的字体高度。
6.相对行间距,0表示0个像素。
实际行间距等于这两者的和。
7.还不知道是什么意思,参数名是boolean includepad。
需要指出的是这个layout是默认画在Canvas的(0,0)点的,如果需要调整位置只能在draw之前移Canvas的起始坐标
canvas.translate(x,y);
Android bitmap绘制文字自动换行的更多相关文章
- android精确绘制文字位置的方法
android 中使用Canvas的drawText绘制文本的位置,是基于基线的. 例如以下图: 当中字母Q的小尾巴在横线以下了. 怎么样找准字母的中心位置呢? 先看以下的样例:(右边的数字,表示字体 ...
- Android - 利用扩展函数为Bitmap添加文字水印
<异空间>项目技术分享系列--扩展函数为Bitmap添加文字水印 对图片Bitmap绘制文字水印还是比较常见的需求,毕竟版权意识都在增强(用户可以给自己图片加上用户名),还可以为用户提供更 ...
- 微信小程序生成海报分享:canvas绘制文字溢出如何换行
主要思路: 1.先分割为字符串数组,然后一个字一个字绘图,利用ctx.measureText(string) 方法,获取绘制后的宽度,判断宽度在多少内就另起一行,再将各行拼成一个字符串 2.计算另起的 ...
- 【朝花夕拾】Android自定义View篇之(三)Canvas绘制文字
前言 转载请声明,转自[https://www.cnblogs.com/andy-songwei/p/10968358.html],谢谢! 前面的文章中在介绍Canvas的时候,提到过后续单独讲Can ...
- Android 使用View绘制文字(DrawText)技术总结
转载请注明出处: http://www.cnblogs.com/renhui/p/7453534.html 这里的绘制文字不是直接调用TextView.setText(String content)去 ...
- Android 使用Canvas在图片上绘制文字
一个小应用,在图片上绘制文字,以下是绘制文字的方法,并且能够实现自动换行,字体自动适配屏幕大小 private void drawNewBitmap(ImageView imageView, Stri ...
- Android绘制文字时垂直居中
canvas.drawText(String text, float x, float y, Paint paint); 是Android中绘制文本的方法,其中的x代表文字绘制时在X轴的起始点,而y是 ...
- 微信小程序-canvas绘制文字实现自动换行
在使用微信小程序canvas绘制文字时,时常会遇到这样的问题:因为canvasContext.fillText参数为 我们只能设置文本的最大宽度,这就产生一定的了问题.如果我们绘制的文本长度不确定或者 ...
- C# 在Bitmap上绘制文字出现锯齿的问题
解决锯齿问题主要是修改Graphics的属性 修复绘制图片锯齿问题可以修改 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiA ...
随机推荐
- 一个统一将数据转换为JSON的方法
这是我得方法: 导包: import net.sf.json.JSONArray; import net.sf.json.JSONObject; public void writeJson(Objec ...
- CSS min-height不能解决垂直外边距合并问题
垂直外边距合并有一种情况是嵌套元素的垂直外边距合并,当父级元素没有设定外边距时,在顶部或者底部边缘的子元素的垂直外边距就会和父级的合并,导致父级也有了“隐形”的垂直外边距. 当父级元素的min-hei ...
- AJAX - 基本流程和特点
<script> window.onload = function(ev){ var oBtn = document.querySelector('button'); // querySe ...
- [React & Testing] Simulate Event testing
Here we want to test a toggle button component, when the button was click, state should change, styl ...
- Python基础教程之第1章 基础知识
#1.1 安装Python #1.1.1 Windows #1.1.2 Linux和UNIX #1.1.3 Macintosh #1.1.4 其它公布版 #1.1.5 时常关注.保持更新 #1.2 交 ...
- Beginning iOS Programming
Beginning iOS Programming 2014年 published by Wrox
- [Angular] Implement a custom form component by using control value accessor
We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...
- php字符串函数分类总结
php字符串函数分类总结 一.总结 explode str_split str_word_count strtolower 二.php字符串函数分类总结 php内置了98个字符串函数(除了基于正 ...
- 5、list列表常用方法说明
创建列表: 1 2 3 name_list = ['alex', 'seven', 'eric'] 或 name_list = list(['alex', 'seven', 'eric']) 基本操作 ...
- UVA 10340 - All in All 水~
看题传送门 Problem E All in All Input: standard input Output: standard output Time Limit: 2 seconds Memor ...