|
|
|
@ -0,0 +1,29 @@
|
|
|
|
|
using System;
|
|
|
|
|
using Models.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace Models.Game
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converter to Base64
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Base64Converter : IImageConverter
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts an image to a base64 string
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="imagePath">The path to access the image</param>
|
|
|
|
|
/// <returns>The base64 string representation of the image</returns>
|
|
|
|
|
/// <exception cref="FileNotFoundException">Native .NET exception</exception>
|
|
|
|
|
public string ConvertImage(string imagePath)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(imagePath))
|
|
|
|
|
{
|
|
|
|
|
// native .NET exception
|
|
|
|
|
throw new FileNotFoundException("Image file not found", imagePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] imageBytes = File.ReadAllBytes(imagePath);
|
|
|
|
|
return Convert.ToBase64String(imageBytes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|