我想拍一张小日历图像并在上面写上日期和月份。这将在列表视图中多次显示,因此我正在寻找最佳方法。
下面的效果很好,有没有更好的方法:
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 ();
}