// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Drawing; using System.IO; namespace Microsoft.PowerToys.FilePreviewCommon { /// /// Represents a bgcode thumbnail. /// public class BgcodeThumbnail { /// /// Gets the bgcode thumbnail image format. /// public BgcodeThumbnailFormat Format { get; } /// /// Gets the bgcode thumbnail image data. /// public byte[] Data { get; } /// /// Initializes a new instance of the class. /// /// The bgcode thumbnail image format. /// The bgcode thumbnail image data. public BgcodeThumbnail(BgcodeThumbnailFormat format, byte[] data) { Format = format; Data = data; } /// /// Gets a representing this thumbnail. /// /// A representing this thumbnail. public Bitmap? GetBitmap() { switch (Format) { case BgcodeThumbnailFormat.JPG: case BgcodeThumbnailFormat.PNG: return BitmapFromByteArray(); case BgcodeThumbnailFormat.QOI: return BitmapFromQoiByteArray(); default: return null; } } private Bitmap BitmapFromByteArray() { return new Bitmap(new MemoryStream(Data)); } private Bitmap BitmapFromQoiByteArray() { return QoiImage.FromStream(new MemoryStream(Data)); } } }