/// <summary> /// Gets the number of bits per pixels for a WIC <see cref="WIC.PixelFormat"/> Guid. /// </summary> /// <param name="targetGuid">A WIC <see cref="WIC.PixelFormat"/> Guid.</param> /// <returns>The number of bits per pixels for a WIC. If this method is failing to calculate the number of pixels, return 0.</returns> private static int GetBitsPerPixel(Guid targetGuid) { using (var info = new WIC.ComponentInfo(Factory, targetGuid)) { if (info.ComponentType != WIC.ComponentType.PixelFormat) { return(0); } var pixelFormatInfo = info.QueryInterfaceOrNull <WIC.PixelFormatInfo>(); if (pixelFormatInfo == null) { return(0); } int bpp = pixelFormatInfo.BitsPerPixel; pixelFormatInfo.Dispose(); return(bpp); } }
/// <summary> /// Function to retrieve the bits per pixel in the specified WIC image format. /// </summary> /// <param name="wicPixelFormat">Image format to look up.</param> /// <returns>The bits per pixel of the format, or -1 if the format/bpp could not be determined.</returns> public int GetBitsPerPixel(Guid wicPixelFormat) { using (var component = new WIC.ComponentInfo(Factory, wicPixelFormat)) { if (component.ComponentType != WIC.ComponentType.PixelFormat) { return(-1); } using (var formatInfo = component.QueryInterfaceOrNull <WIC.PixelFormatInfo>()) { if (formatInfo == null) { return(-1); } return(formatInfo.BitsPerPixel); } } }
/// <summary> /// Gets the number of bits per pixels for a WIC <see cref="WIC.PixelFormat"/> Guid. /// </summary> /// <param name="targetGuid">A WIC <see cref="WIC.PixelFormat"/> Guid.</param> /// <returns>The number of bits per pixels for a WIC. If this method is failing to calculate the number of pixels, return 0.</returns> private static int GetBitsPerPixel(Guid targetGuid) { using (var info = new ComponentInfo(Factory, targetGuid)) { if (info.ComponentType != ComponentType.PixelFormat) return 0; var pixelFormatInfo = info.QueryInterfaceOrNull<PixelFormatInfo>(); if (pixelFormatInfo == null) return 0; int bpp = pixelFormatInfo.BitsPerPixel; pixelFormatInfo.Dispose(); return bpp; } }