Canvas drawText

1292 ワード

String str=「テスト文字列」
  int len = str.getBytes().length;  int w = len *16;  int h =32;  Bitmap strBitmap =Bitmap.createBitmap(w, h,Bitmap.Config.RGB_565);  Canvas c =newCanvas(strBitmap);  Paint paint =newPaint(Paint.ANTI_ALIAS_FLAG);  paint.setTextSize(35);  Typeface tf =Typeface.createFromAsset(getAssets(),"caiyun");  paint.setTypeface(tf);  paint.setColor(0xFFFFFFFF);  paint.setTextAlign(Align.LEFT);
  FontMetrics fm = paint.getFontMetrics();  c.drawText(str,0, h + fm.top - fm.ascent, paint);  c.save();
 
  c.drawText(str, 0, h + fm.top - fm.ascent, paint);
 , “h + fm.top - fm.ascent” ,h ( bitmap , h bitmap ),fm.top - fm.ascent baseline,  Canvas.drawText :
Draw the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the Align setting in the paint. 

Parameters:
text The text to be drawn
x The x-coordinate of the origin of the text being drawn
y The y-coordinate of the origin of the text being drawn
paint The paint used for the text (e.g. color, size, style)
このoriginは文字baselineベースラインの座標です.
 
 Typeface, , , ,
Typeface.createFromAsset(getAssets(), "caiyun");