Newbie question on getting Pixel Format from an image #2682
-
Hello! Is there a way to know what pixel / color format is used in the original image? For example, I want to know whether the original pixel format is in I am working with .png, .jpg, .tiff, .bmp and .tga, and then converting them into .dds format. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Note that System.Drawing's ImageSharp will also pick an arbitrary pixel format when using the non-generic // The sample is using 3.1.* API
ImageInfo info = Image.Identify("my.png");
PixelTypeInfo pixelType = info.PixelType;
Console.WriteLine($"bpp: {pixelType.BitsPerPixel}");
// There is no way to get more information from pixelType at the moment,
// however you can observe format specific information:
if (info.Metadata.TryGetPngMetadata(out PngMetadata pngMetadata))
{
// pngMetadata has plenty of properties
}
If you are resaving the image anyways, I wonder what do you need the pixel format information for? |
Beta Was this translation helpful? Give feedback.
Note that System.Drawing's
Image.PixelFormat
doesn't necessarily represent the format used in the "original image", if you mean the encoded file by that. While it's correct for a PNG, note that JPEG stores images in YCbCr color space, meaning if you don't ask for a specific format when decoding, the outcome,new Bitmap("img.jpg").PixelFormat == PixelFormat.Format24bppRgb
is not really accurate. Long story shortImage.PixelFormat
is the format System.Drawing decides to internally represent your image in when you are not asking for a specific format at decoding, and not the absolute thruth about the source image.ImageSharp will also pick an arbitrary pixel format when using the non-generic
I…