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