我想拍一张小日历图片并在上面写上日期和月份。这将在 ListView 中多次显示,因此我正在寻找最佳方法。
下面很好用,有没有更好的办法:
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 ();
}
最佳答案
你为什么不直接使用 ImageView,并在其上放置一个 TextView 作为标题的覆盖层,放在启用此功能的布局容器内 - 例如RelativeLayout 还是 FrameLayout?
我有几个项目用这种方式在图像上写标题,这种方法没有问题。
关于android - 在图像上写文字的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10164590/