我正在嘗試使用此代碼繪製頭像位圖。但是位圖是像素化的。這是我的代碼。目前我使用createScaledBitmap來調整頭像圖片的大小。此外,文字在高分辨率的某些設備上稍小一些在畫布上繪製位圖時出現質量不佳
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inMutable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.card_nodpi, opt) ;
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(40);
paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
canvas.drawText("The quick brown fox", x, y, paint);
Paint paint2 = new Paint();
paint2.setColor(Color.BLACK);
paint2.setTextSize(30);
canvas.drawText("The quick brown fox", x, y + (40), paint2);
canvas.drawText("The quick brown fox", x, y + ((40 * 2)), paint2);
if (avatar != null) {
Bitmap img = Bitmap.createScaledBitmap(avatar, 250, 250, false);
canvas.drawBitmap(img, bitmap.getWidth() - img.getWidth() - x, y - 40, new Paint(Paint.FILTER_BITMAP_FLAG));
}
imageView.setImageBitmap(bitmap);
沒有錯的代碼之前......你確定你的頭像是不太多小? R.drawable.card_nodpi有多大? – Kasra 2015-02-12 04:21:46
大小爲1,016 x 638 – 2015-02-12 05:05:42