1
我想拍一張小日曆圖像並在上面寫上日期和月份。這將在列表視圖中顯示很多次,所以我正在尋找最佳方式來做到這一點。在圖片上寫文字的最佳方法?
下面的偉大工程,是沒有更好的方法:
ImageView image = (ImageView) findViewById(R.id.imageView2);
try {
// Load the png image into a bitmap
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.calendar_empty);
// Have to copy the bitmap so it is mutable
mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
// Create a canvas from the bitmap to draw on
Canvas canvas = new Canvas(mBitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(12);
paint.setAntiAlias(true);
canvas.drawText("Sept", 11, 26, paint);
paint.setTextSize(18);
canvas.drawText("29", 14, 42, paint);
// Display the results on the screen
image.setImageDrawable(new BitmapDrawable(this.getResources(), mBitmap));
} catch (Exception e) {
e.printStackTrace();
}
使用疊加方法,您是否必須獲得顯示密度並相應地縮放所有計算?通過上述方法,android系統會自動調整圖像大小。 – pcm2a 2012-04-15 20:09:48
您的意思是,如果TextView小部件中的文本物理大小在不同屏幕密度的設備上保持不變?如果是這樣,那麼是的,TextView照顧,你可以在dip中定義textSize。 – 2012-04-15 21:01:46
這和圖像視圖上文字的位置。例如,根據屏幕的密度,100像素x 100像素的圖像可能是70像素或150像素。我想要將我的文字X,Y像素放置在所有分辨率上並完美對齊。 – pcm2a 2012-04-15 22:01:09