文字轉Bitmap的一個方法

直接上代碼

public Bitmap getNewBitMap(String text,int height,int width) {
        Bitmap newBitmap = Bitmap.createBitmap(width,height, Config.ARGB_4444);
        Canvas canvas = new Canvas(newBitmap);
        canvas.drawBitmap(newBitmap, 0, 0, null);
        TextPaint textPaint = new TextPaint();
        textPaint.setAntiAlias(true);
        textPaint.setTextSize(height*2/3);
        textPaint.setColor(Color.rgb(0, 0, 0));
        StaticLayout sl= new StaticLayout(text, textPaint, newBitmap.getWidth(), Layout.Alignment.ALIGN_CENTER,1.0f, 0.0f, false);
        canvas.translate(0,height/10);
        sl.draw(canvas);
        return newBitmap;
    }

只是爲了滿足我的一個需求而設置的代碼結構:
從通訊錄中獲取聯繫人,然後用聯繫人名稱的一個字做出圖片,然後展示給用戶。(其他不適應的條件勿噴)

發佈了29 篇原創文章 · 獲贊 9 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章