In C# I can declare new 48bitRGB
or 64bitRGBA
without problem, and in fact the right format is saved on disk.
However, when it comes to declaring a color, I am not able to declare color of more than 8-bit values. That seems to be because Color
declarations expect no more than 8 bits per component.
The code I have so far:
int x;
int y;
int w = 512, h = 512;
Bitmap image = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format48bppRgb); //New image with 16bit per channel, no problem
// Double 'for' control structure to go pixel by pixel on the whole image
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
comp = somevalue; //Numeric component value
// Lo que vaya por aqui
System.Drawing.Color newColor = System.Drawing.Color.FromArgb(255, comp, comp, comp); // <= Here is the problem, values can't exceed 256 levels
image.SetPixel(x, y, newColor);
}
}
image.Save(@"C:\test.png", System.Drawing.Imaging.ImageFormat.Png); //Saving image to disk
What is a method for declaring a 16-bit color component in C#?
Using 16 bits per color channel produces 48 bits, 281,474,976,710,656 colors. If an alpha channel of the same size is added then there are 64 bits per pixel.
The available bit depth settings depend on the file type. Standard JPEG and TIFF files can only use 8-bits and 16-bits per channel, respectively.
Up to 65,536 colors can be represented in the color palette. Most graphics formats provide 8-bit color or 24-bit color; however, graphics cards generally have an intermediate 16-bit color range that displays 65,536 colors. See color depth.
With a 64-bit system, each plane is represented by 16 bits. The doubling of the number of bits increases the resolution of each color to 2 to the power of 16, so instead of the 256 levels per color in a 32-bit system, we now have 65536.
The problem stems from the fact that the Bitmap class encapsulates a GDI+ bimap.
GDI+ version 1.0 and 1.1 can read 16-bits-per-channel images, but such images are converted to an 8-bits-per-channel format for processing, displaying, and saving. link
So when you are setting the value of the pixels you are dealing with the 8 bit per channel format.
If use use unsafe code you can access the values directly, see Get 64bpp image color.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With