Getting PixelFormat from Jpeg #1293
-
Hi! Does anybody know, if there is a way to determine the PixelFormat of an image (jpg) dynamically using ImageSharp. With JpgBitmapDecoder from WPF, a frame has this information available in the format property. https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.pixelformat?view=netcore-3.1 https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.PixelFormats.html Did not find anything regarding this in the docs. Appreciate any help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 18 replies
-
ImageSharp works a little differently... The You can however get the original bit depth from a jpeg via
|
Beta Was this translation helpful? Give feedback.
-
@christian-be can you elaborate on your use case? Why is that information useful? What decisions does your app make based on the pixel format? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick replies! We are using ImageSharp to crop images before sending them to an external 3rd-party OCR-engine. This library expects an enum to be passed alongside the image-stream containing this information. (Bgr24 | Bgr32 | Gray8...etc). What I can see from @JimBobSquarePants answer is, that it's easy to detect the pixel-depth of the image, but how to determine if it is RGB, Gray, BW? |
Beta Was this translation helpful? Give feedback.
ImageSharp works a little differently...
The
PixelFormat
is imperative, i.e. determined by the generic type parameter given toImage<TPixel>
. The non-generic variant currently defaults toRgba32
but we may change that in the future as we optimize each decoder.You can however get the original bit depth from a jpeg via
PixelType
property on the image. You can use the variousIdentify
methods to get this information without fully decoding the image to should you choose to do so.Identify
and co are super, super fast so you could use them to determine the bit depth and theIImageFormat
which would allow you to create optimized paths for each image format and then decode along those paths.