zoukankan      html  css  js  c++  java
  • android bitmap绘制文字自动换行

    public Bitmap getNewBitMap(String text) {
            Bitmap newBitmap = Bitmap.createBitmap(120,150, Config.ARGB_4444);
            Canvas canvas = new Canvas(newBitmap);
            canvas.drawBitmap(bmp, 0, 0, null);
            TextPaint textPaint = new TextPaint();
            textPaint.setAntiAlias(true);
            textPaint.setTextSize(16.0F);
            StaticLayout sl= new StaticLayout(text, textPaint, newBitmap.getWidth()-8, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            canvas.translate(6, 40);
            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);

  • 相关阅读:
    Codefores 506A Mr. Kitayuta, the Treasure Hunter( DP && dfs )
    Goals ? Ideals ?
    HDU 5159 Card( 计数 期望 )
    HDU 1387 Team Queue( 单向链表 )
    HDU 1709 The Balance( DP )
    HDU 2152 Fruit( DP )
    HDU 1398 Square Coins(DP)
    HDU 5155 Harry And Magic Box( DP )
    HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )
    最大连续自序列
  • 原文地址:https://www.cnblogs.com/error404/p/2876901.html
Copyright © 2011-2022 走看看