<PackageReference Include="System.Drawing.Common" Version="9.0.2" />

ImageCodecInfo

public sealed class ImageCodecInfo
The ImageCodecInfo class provides the necessary storage members and methods to retrieve all pertinent information about the installed image encoders and decoders (called codecs). Not inheritable.
using System.Runtime.CompilerServices; using Windows.Win32; using Windows.Win32.Graphics.GdiPlus; namespace System.Drawing.Imaging { [NullableContext(2)] [Nullable(0)] public sealed class ImageCodecInfo { public Guid Clsid { get; set; } public Guid FormatID { get; set; } public string CodecName { get; set; } public string DllName { get; set; } public string FormatDescription { get; set; } public string FilenameExtension { get; set; } public string MimeType { get; set; } public ImageCodecFlags Flags { get; set; } public int Version { get; set; } [Nullable(new byte[] { 2, 1 })] [CLSCompliant(false)] [field: Nullable(new byte[] { 2, 1 })] public byte[][] SignaturePatterns { [return: Nullable(new byte[] { 2, 1 })] get; [param: Nullable(new byte[] { 2, 1 })] set; } [Nullable(new byte[] { 2, 1 })] [CLSCompliant(false)] [field: Nullable(new byte[] { 2, 1 })] public byte[][] SignatureMasks { [return: Nullable(new byte[] { 2, 1 })] get; [param: Nullable(new byte[] { 2, 1 })] set; } internal ImageCodecInfo() { } [NullableContext(1)] public unsafe static ImageCodecInfo[] GetImageDecoders() { uint num = default(uint); uint num2 = default(uint); PInvoke.GdipGetImageDecodersSize(&num, &num2).ThrowIfFailed(); BufferScope<byte> bufferScope = new BufferScope<byte>((int)num2); try { ImageCodecInfo[] result; fixed (byte* ptr = &bufferScope.GetPinnableReference()) { PInvoke.GdipGetImageDecoders(num, num2, (global::Windows.Win32.Graphics.GdiPlus.ImageCodecInfo*)ptr).ThrowIfFailed(); result = FromNative(new ReadOnlySpan<global::Windows.Win32.Graphics.GdiPlus.ImageCodecInfo>(ptr, (int)num)); } return result; } finally { bufferScope.Dispose(); } } [NullableContext(1)] public unsafe static ImageCodecInfo[] GetImageEncoders() { GdiPlusInitialization.EnsureInitialized(); uint num = default(uint); uint num2 = default(uint); PInvokeCore.GdipGetImageEncodersSize(&num, &num2).ThrowIfFailed(); BufferScope<byte> bufferScope = new BufferScope<byte>((int)num2); try { ImageCodecInfo[] result; fixed (byte* ptr = &bufferScope.GetPinnableReference()) { PInvokeCore.GdipGetImageEncoders(num, num2, (global::Windows.Win32.Graphics.GdiPlus.ImageCodecInfo*)ptr).ThrowIfFailed(); result = FromNative(new ReadOnlySpan<global::Windows.Win32.Graphics.GdiPlus.ImageCodecInfo>(ptr, (int)num)); } return result; } finally { bufferScope.Dispose(); } } [NullableContext(0)] [return: Nullable(1)] private unsafe static ImageCodecInfo[] FromNative(ReadOnlySpan<global::Windows.Win32.Graphics.GdiPlus.ImageCodecInfo> codecInfo) { ImageCodecInfo[] array = new ImageCodecInfo[codecInfo.Length]; for (int i = 0; i < codecInfo.Length; i++) { int sigCount = (int)codecInfo[i].SigCount; ImageCodecInfo imageCodecInfo = new ImageCodecInfo { Clsid = codecInfo[i].Clsid, FormatID = codecInfo[i].FormatID, CodecName = codecInfo[i].CodecName.ToString(), DllName = codecInfo[i].DllName.ToString(), FormatDescription = codecInfo[i].FormatDescription.ToString(), FilenameExtension = codecInfo[i].FilenameExtension.ToString(), MimeType = codecInfo[i].MimeType.ToString(), Flags = codecInfo[i].Flags, Version = codecInfo[i].Version, SignaturePatterns = new byte[sigCount][], SignatureMasks = new byte[sigCount][] }; for (int j = 0; j < sigCount; j++) { byte[][] signaturePatterns = imageCodecInfo.SignaturePatterns; int num = j; ReadOnlySpan<byte> readOnlySpan = new ReadOnlySpan<byte>(codecInfo[i].SigPattern + j * codecInfo[i].SigSize, (int)codecInfo[i].SigSize); signaturePatterns[num] = readOnlySpan.ToArray(); byte[][] signatureMasks = imageCodecInfo.SignatureMasks; int num2 = j; readOnlySpan = new ReadOnlySpan<byte>(codecInfo[i].SigMask + j * codecInfo[i].SigSize, (int)codecInfo[i].SigSize); signatureMasks[num2] = readOnlySpan.ToArray(); } array[i] = imageCodecInfo; } return array; } } }