Text Rendered over bitmap
I 'd like to know how can I render a text o开发者_StackOverflow中文版ver a 48x48 bitmap in my android application, considering sometimes the text exceeds the bitmap width .In such cases I need to render only a part of the text followed by dots such that all fits the available width !
Thanks !
Update, Here's the code I used:
Bitmap renderSurface = icon.createBitmap();
Canvas canvas = new Canvas(renderSurface);
Paint paint = new Paint();
paint.setTextSize(10);
if(paint.measureText(nativeName)>canvas.getWidth())
nativeName = getClippedString(paint,nativeName,canvas.getWidth() );
canvas.drawText(nativeName,33,0, paint);
return renderSurface;
You have to create another Bitmap (unless the original Bitmap is mutable) and then create a Canvas to draw on that Bitmap. Finally, just call drawText() on the Canvas. To know where to ellipsize your text, you can use the Paint's class text measurement methods.
精彩评论