图片上添加文字,获取文字长度错误

今天用到在bitmap上面写字符串,但是通过

TextPaint textPaint2 = new TextPaint() ;
textPaint2 .setTextSize(numSize2 ) ;
textPaint2 .setFakeBoldText(true ) ;
textPaint2 .setColor(Color.rgb (255 , 255, 255 ));
textPaint2 .setTextAlign(Align. LEFT) ;
float areaTextLength = textPaint.measureText(carCount) ;

获取的字符串长度不正确,分别传入不同的字符串,返回的长度一样
经过查询和测试找到了正确的方法

TextView textView = new TextView( context) ;
Paint textPaint = textView .getPaint();
float carTextLength = textPaint .measureText(carCount) ;

返回的字符串为正常的
参考http://blog.csdn.net/lizzy115/article/details/7513552

你可能感兴趣的:(图片上添加文字,获取文字长度错误)