using XFEExtension.NetCore.ImplExtension;
namespace XFEExtension.NetCore.XApp.Core;
///
/// XApp图片文件
///
/// 文件类型
/// 文件名
/// 图片Base64字符串
/// 图片类型
public abstract class XAppImage(XAppFileType fileType, string fileName, string imageBase64String, ImageType imageType) : XAppFile(fileType, fileName, imageBase64String)
{
///
/// 图片Base64字符串
///
public string ImageBase64String { get; set; } = imageBase64String;
///
/// 图片类型
///
public ImageType ImageType { get; set; } = imageType;
///
/// 从图片中读取
///
/// 文件类型
/// 文件名
///
public static XAppImage FromImage(XAppFileType xAppFileType, string fileName) => new XAppImageImpl(xAppFileType, fileName, Convert.ToBase64String(File.ReadAllBytes(fileName)), GetImageType(Path.GetExtension(fileName)));
///
/// 获取图片类型
///
/// 文件扩展名
///
///
public static ImageType GetImageType(string extension) => extension.ToLower() switch
{
".png" => ImageType.Png,
".jpg" => ImageType.Jpg,
".jpeg" => ImageType.Jpeg,
".bmp" => ImageType.Bmp,
".gif" => ImageType.Gif,
_ => throw new XAppException("不支持的图片格式")
};
}