I would just like to share my solution, which I found after some research and worked well.
var btnSave = FindViewById<Button>(Resource.Id.btnSave);
btnSave.Click += async delegate
{
if (signature.IsBlank)
{
// display the base line for the user to sign on.
Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
alert.SetMessage(Resources.GetString(Resource.String.signature_isempty));
alert.SetNeutralButton("OK", delegate { });
alert.Create().Show();
}
else
{
points = signature.Points;
try
{
string nString = String.Format("mySign_{0}.png", Guid.NewGuid());
string absolutePath = String.Format("{0}/{1}", Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString(), GetString(Resource.String.app_name).ToString());
var filePath = System.IO.Path.Combine(absolutePath, nString);
/**
You can get base64 and save your database
**/
/*var img = await signature.GetImageStreamAsync(SignatureImageFormat.Jpeg);
var signatureMemoryStream = (MemoryStream)img;
byte[] data = signatureMemoryStream.ToArray();
string base64img = Convert.ToBase64String(data);
Log.Info(NativeConfig.TAG_DROID, base64img.ToString());
File.WriteAllBytes(filePath, data);*/
var img = await signature.GetImageStreamAsync(SignatureImageFormat.Png, Color.Black, Color.White, true);
var ms = (MemoryStream)img;
using (FileStream file = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[ms.Length];
ms.Read(bytes, 0, (int)ms.Length);
file.Write(bytes, 0, bytes.Length);
ms.Close();
}
}
catch (Exception e)
{
Log.Info(NativeConfig.TAG_DROID, e.Message);
Toast.MakeText(this, "No se pudo guardar", ToastLength.Short).Show();
}
}
};
btnSave.Dispose();
I adapted the code from the sample page and added the filestream.