public virtual string GetColorTypeDescription() { int?value = _directory.GetInteger(PngDirectory.TagColorType); if (value == null) { return(null); } PngColorType colorType = PngColorType.FromNumericValue((int)value); if (colorType == null) { return(null); } return(colorType.GetDescription()); }
public static Metadata ParsePngDirectory(PngDirectory directory, Metadata metadata) { if (directory.TryGetInt32(PngDirectory.TagImageWidth, out var width)) { metadata.Image.Width = width; } if (directory.TryGetInt32(PngDirectory.TagImageHeight, out var height)) { metadata.Image.Height = height; } if (directory.TryGetInt32(PngDirectory.TagColorType, out var colorTypeId)) { var colorType = PngColorType.FromNumericValue(colorTypeId); metadata.Image.PngColorType = colorType.Description; int?numberOfComponents = null; if (colorType == PngColorType.Greyscale) { numberOfComponents = 1; } else if (colorType == PngColorType.TrueColor) { numberOfComponents = 3; } else if (colorType == PngColorType.GreyscaleWithAlpha) { numberOfComponents = 2; } else if (colorType == PngColorType.TrueColorWithAlpha) { numberOfComponents = 4; } int?dataPrecision = null; if (directory.TryGetInt32(PngDirectory.TagBitsPerSample, out var bitsPerSample)) { dataPrecision = bitsPerSample; } if (dataPrecision != null) { if (numberOfComponents != null) { metadata.Image.BitDepth = (int)(numberOfComponents * dataPrecision); } else { metadata.Image.DataPrecision = (int)dataPrecision; } } } if (directory.TryGetDouble(PngDirectory.TagGamma, out var gamma)) { metadata.Image.Gamma = gamma; } if (directory.ContainsTag(PngDirectory.TagCompressionType)) { metadata.Image.CompressionType = directory.GetDescription(PngDirectory.TagCompressionType); } if (directory.ContainsTag(PngDirectory.TagInterlaceMethod)) { metadata.Image.InterlaceMethod = directory.GetDescription(PngDirectory.TagInterlaceMethod); } return(metadata); }