Search code examples
xamarinxamarin.formsstreamsignaturepad

Save image from stream and get file path


I want to save the image of my signature pad in my device and get the file path where I saved the image. I am using xamarin-controls-signature-pad nuget package to capture my signature. Please see my code below:

Stream sigimage = await Signature.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Png);

string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), signatureFile);

using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
   await sigimage.CopyToAsync(fileStream);
}

if (File.Exists(fileName))
{
    await DisplayAlert("File", "File exist", "ok");
}
else
{
    await DisplayAlert("File", "File does not exist", "ok");
}

enter image description here


Solution

  • see File Handling in Xamarin Forms

    string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "sig.png");
    
    using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
      {
        image.CopyTo(fileStream);
      }