Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64-bit image color declaring (16 bit per channel)

Tags:

c#

image

colors

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#?

like image 406
Vicente Carratala Avatar asked May 22 '15 09:05

Vicente Carratala


People also ask

How many bits per channel does 16-bit color have?

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.

Can an image have a 16 bits per channel bit depth?

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.

How many colors are in the color table for a 16-bit image?

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.

How many colors does 64 bit have?

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.


1 Answers

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.

like image 128
Stephen Turner Avatar answered Oct 21 '22 05:10

Stephen Turner