C# Code
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap("E://Android tools//dome//WindowsFormsApplication1//WindowsFormsApplication1//Image//bmp.jpeg");
Graphics graphics = Graphics.FromImage(bmp);
graphics.DrawString(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"), new Font("Arial", 32), new SolidBrush(Color.Green), bmp.Width - 420, bmp.Height - 60);
string path = "./" + "Image/";
if (File.Exists(path))
File.Create(path);
path+= DateTime.Now.ToString("hhmmss").Replace(" ", "") + ".jpeg";
bmp.Save(path);
bmp.Dispose();
}
如下图:
Android Code mono C#
public byte[] BitmapBytes(Bitmap bimp,string path)
{
Bitmap newb = null;
string date = "";
if (bimp != null)
{
try
{
//取得图片属于信息
ExifInterface exif = new ExifInterface(path);
if (exif != null)
{
date = exif.GetAttribute("DateTime") !=""?System.Convert.ToDateTime(exif.GetAttribute("DateTime")).ToString("yyyy/MM/dd hh:mm:ss") : "";
}
}
catch
{
throw;
}
int w = bimp.Width;
int h = bimp.Height;
Paint p = new Paint();
p.Color = Color.Green;
p.TextSize = 12;
Typeface font = Typeface.Create("Arial", TypefaceStyle.Normal);
p.SetTypeface(font);
//创建一个一模一样的位图的底图
newb = Bitmap.CreateBitmap(w,h,Bitmap.Config.Argb8888);
Canvas cv = new Canvas(newb);
//复制原图
cv.DrawBitmap(bimp, 0, 0, null);
//打上水印日期
cv.DrawText(date, w-160, h -20, p);
cv.Save(SaveFlags.All);
cv.Restore();
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
newb.Compress(Bitmap.CompressFormat.Jpeg, 100, ms);
return ms.ToArray();
}