5using System.Threading.Tasks;
180 else if (ContentType.StartsWith(
"image/"))
202 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
203 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
205 SKBitmap Bitmap = SKBitmap.Decode(Data);
206 return Task.FromResult(
new ContentResponse(ContentType, SKImage.FromBitmap(Bitmap), Data));
218 if ((Object is SKImage || Object is SKBitmap) &&
239 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
ICodecProgress Progress, params
string[] AcceptedContentTypes)
242 bool Dispose =
false;
246 if (!(Object is SKImage Image))
248 if (Object is SKBitmap Bitmap)
250 Image = SKImage.FromBitmap(Bitmap);
254 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Object not an image derived from SkiaSharp.SKImage or SkiaSharp.SKBitmap.", nameof(Object))));
259 Data = Image.Encode(SKEncodedImageFormat.Webp, 100);
264 Data = Image.Encode(SKEncodedImageFormat.Png, 100);
269 Data = Image.Encode(SKEncodedImageFormat.Bmp, 100);
274 Data = Image.Encode(SKEncodedImageFormat.Jpeg, 90);
279 Data = Image.Encode(SKEncodedImageFormat.Gif, 100);
284 Data = Image.Encode(SKEncodedImageFormat.Ico, 100);
288 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object))));
290 Bin = Data.ToArray();
307 switch (FileExtension.ToLower())
352 ContentType =
string.Empty;
365 switch (ContentType.ToLower())
408 FileExtension =
string.Empty;
Contains information about a response to a content request.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
const string FileExtensionJpg
jpg
const string ContentTypeJpg
image/jpeg
const string ContentTypeIcon
image/x-icon
const string ContentTypeWebP
image/webp
const string ContentTypeEmf
image/x-emf
const string ContentTypeGif
image/gif
static readonly string[] ImageFileExtensions
Image content types.
const string FileExtensionPng
png
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
const string FileExtensionWebP
webp
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
const string FileExtensionWmf
wmf
const string FileExtensionIcon
ico
string[] ContentTypes
Supported content types.
const string ContentTypePng
image/png
const string FileExtensionEmf
emf
ImageCodec()
Image encoder/decoder.
const string FileExtensionSvg
svg
const string ContentTypeBmp
image/bmp
const string ContentTypeTiff
image/tiff
const string ContentTypeWmf
image/x-wmf
const string ContentTypeSvg
image/svg+xml
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
const string FileExtensionGif
gif
string[] FileExtensions
Supported file extensions.
const string FileExtensionBmp
bmp
const string FileExtensionTiff
tif
static readonly string[] ImageContentTypes
Image content types.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...