SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm”, Locale.CHINA);
String date = sdf.format(new Date());
Bitmap.Config bitmapConfig = bitmap.getConfig();
// set default bitmap config if none
if (bitmapConfig == null) {
bitmapConfig = Bitmap.Config.ARGB_8888;
}
bitmap = bitmap.copy(bitmapConfig, true); // 获取可改变的位图
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// text color - #3D3D3D
paint.setColor(Color.RED);
// text size in pixels
paint.setTextSize(30);
// text shadow
// paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
Rect bounds = new Rect();
paint.getTextBounds(date, 0, date.length(), bounds);
int x = (bitmap.getWidth() - bounds.width());
canvas.drawText(date, x - 10, bitmap.getHeight() - 10, paint);
canvas.save();
return bitmap;
}

2.如果是从图库选择的照片,我们需要先获取照片拍摄日期,然后再将日期画上去,代码如下:

//从图库选择
private void fromGallery(Intent data, OnFilishedListener listener) {
Uri uri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA , MediaStore.Images.Media.DATE_TAKEN};
Cursor cursor = null;
if (uri == null)
return;
if (uri.getScheme().contains(“file”)) {
Long fileTime = (new File(uri.getPath())).lastModified();
String dateTime = TimeUtil.longToDate1(fileTime);
Log.i(“wtt”,"照片拍摄日期为dateTime: " + dateTime);
saveSelectPic( dateTime , uri.getPath(), listener);
} else if (uri.getScheme().contains(“content”)) {
if (fragment != null) {
cursor = fragment.getActivity().getContentResolver()
.query(uri, filePathColumn, null, null, null);
} else {
cursor = activity.getContentResolver().
query(uri,filePathColumn, null, null, null);
}
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
int dateIndex = cursor.getColumnIndexOrThrow(filePathColumn[1]);
String date = cursor.getString(dateIndex);
if (TextUtils.isEmpty(date)) {
date = TimeUtil.getStringDate1();
}else{
date = TimeUtil.longToDate1(Long.parseLong(date));
}
cursor.close();
saveSelectPic(date , picturePath, listener);
} else {
listener.onFilish(null);
}
}
}
/**
• 保存圖片
• 
• @param picPath
• @param listener
*/
private void saveSelectPic(String date, String picPath, OnFilishedListener listener) {
if (TextUtils.isEmpty(picPath)) {
listener.onFilish(null);
return;
}
Bitmap bitmap = BitmapUtils.scaleBitmap(picPath);
bitmap = BitmapUtils.drawDate2Bitmap( date , bitmap);
try {
picPath = BitmapUtils.saveBitmap(bitmap);