using System.Drawing; using System.Drawing.Imaging; // Load the original image Image originalImage = Image.FromFile("original.jpg"); // Create a new 8-bit indexed bitmap from the original image Bitmap indexedImage = new Bitmap(originalImage.Width, originalImage.Height, PixelFormat.Format8bppIndexed); // Copy the original image into the new indexed bitmap using (Graphics g = Graphics.FromImage(indexedImage)) { g.DrawImage(originalImage, 0, 0, originalImage.Width, originalImage.Height); } // Save the indexed bitmap as a new file indexedImage.Save("indexed.png", ImageFormat.Png);
using System.Drawing; using System.Drawing.Imaging; // Load the image Image image = Image.FromFile("image.jpg"); // Get the pixel format of the image PixelFormat pixelFormat = image.PixelFormat; // Print the pixel format Console.WriteLine($"Pixel format: {pixelFormat}");This example loads an image from a file and prints its pixel format. This can be useful when debugging image processing code or when determining the capabilities of an image library. This code is part of the System.Drawing.Imaging library.