🖼️ Ajout d'une méthode récupération de l'image depuis la chaine convertie

pull/97/head
Rémi LAVERGNE 1 year ago
parent ac794f5c16
commit b913214afc
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -1,4 +1,5 @@
using System; using System;
using Microsoft.Maui.Controls;
using Models.Interfaces; using Models.Interfaces;
namespace Models.Game namespace Models.Game
@ -25,5 +26,16 @@ namespace Models.Game
byte[] imageBytes = File.ReadAllBytes(imagePath); byte[] imageBytes = File.ReadAllBytes(imagePath);
return Convert.ToBase64String(imageBytes); return Convert.ToBase64String(imageBytes);
} }
/// <summary>
/// Retrieve an image from a string encoded in base64
/// </summary>
/// <param name="imageString"></param>
/// <returns></returns>
public ImageSource RetrieveImage(string imageString)
{
byte[] imageBytes = Convert.FromBase64String(imageString);
return ImageSource.FromStream(() => new MemoryStream(imageBytes));
}
} }
} }

@ -1,4 +1,6 @@
namespace Models.Interfaces using Microsoft.Maui.Controls;
namespace Models.Interfaces
{ {
/// <summary> /// <summary>
/// Interface for image converters /// Interface for image converters
@ -11,5 +13,12 @@
/// <param name="imagePath"></param> /// <param name="imagePath"></param>
/// <returns></returns> /// <returns></returns>
string ConvertImage(string imagePath); string ConvertImage(string imagePath);
/// <summary>
/// Retrieve an image from a string encoded
/// </summary>
/// <param name="imageString"></param>
/// <returns></returns>
ImageSource RetrieveImage(string imageString);
} }
} }

Loading…
Cancel
Save