在filesave.java中做如下修改:
1 添加以下两个函数:
public Bitmap createBitmap(Bitmap src, long dateTaken) {
//
String datetime = DateFormat.format("yyyy:MM:dd kk:mm:ss", dateTaken).toString();
//
int w = src.getWidth();
int h = src.getHeight();
Bitmap bmpTemp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(bmpTemp);
Paint p = new Paint();
String fontName = "serif";
int textSize = 60;
Typeface font = Typeface.create(fontName, Typeface.NORMAL);
p.setColor(Color.BLUE);
p.setTypeface(font);
p.setTextSize(textSize);
canvas.drawBitmap(src, 0, 0, p);
canvas.drawText(datetime, 0, textSize, p);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
return bmpTemp;
}
//
public void compressAndSaveBitmap(Bitmap rawBitmap, String mFilePath, int quality){
File saveFile= new File(mFilePath);
if (saveFile.exists()) {
saveFile.delete();
}
try {
FileOutputStream fileOutputStream = new FileOutputStream(saveFile);
if (fileOutputStream != null) {
rawBitmap.compress(Bitmap.CompressFormat.JPEG, quality, fileOutputStream);
}
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
2 添加以下代码:
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Bitmap.Config;
import android.text.format.DateFormat;
import android.graphics.Rect;
3 在PhotoOperator的saveRequest()中做如下修改:
try {
// Write to a temporary file and rename it to the final name. This
// avoids other apps reading incomplete data.
out = new FileOutputStream(mTempFilePath);
out.write(mData);
out.close();
new File(mTempFilePath).renameTo(new File(mFilePath));
} catch (IOException e) {
Log.e(TAG, "Failed to write image", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
Log.e(TAG, "saveRequest()", e);
}
}
}
//add for timestamp
Log.v(TAG, "mFilePath=" + mFilePath);
try {
ExifInterface exif = new ExifInterface(mFilePath);
String model = exif.getAttribute(ExifInterface.TAG_MODEL);
Bitmap bitmap = BitmapFactory.decodeFile(mFilePath, null);//
Bitmap markbitmap = createBitmap(bitmap, mDateTaken);//
compressAndSaveBitmap(markbitmap, mFilePath, 80);//
//exif.setAttribute(ExifInterface.TAG_MODEL,model);
exif.saveAttributes();
}catch(IOException ex){
Log.e(TAG, " IOException" );
}
// add end
mMimeType = Storage.generateMimetype(mTitle, mTempPictureType);
mMpoType = Storage.generateMpoType(mTempPictureType);
saveImageToDatabase(this);
if (LOG) {
Log.v(TAG, "saveRequest() mTempJpegRotation=" + mTempJpegRotation
+ ", mOrientation=" + mOrientation);
}