Fill a bitmap with 16-bit grayscale values ​​without scaling

I have a file with raw images. Each pixel is represented as 16 bit (0-65536).

I am reading the necessary piece of data into an array ushort[]. After doing some image processing, I need to somehow show this image to the user. I have no problem drawing an 8-bit grayscale (I just set all the R, G, and B values ​​of each pixel), but cannot process a 16-bit / pixel grayscale image.

Another possibility is to use PixelFormat.Format48bppRgband install r, g and b in the same 16-bit grenade, but I could not find it.

I found the code snippets using the code unsafeand LockBits, but could not get them to work.

Is there a way to paint a 16-bit grayscale image without reducing it to 8 bits?

Please provide me the code snippet.

EDIT: this is how I set the 8-bit granules:

Array img;
//var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat);
if (bitsPerElement == 8)
{
    //img = Array.CreateInstance(typeof(byte), bitmapHeigth*bitmapWidth);
    img = GetLayerBytes<byte>(LayerNum) as byte[];
}
else
{
    img = GetLayerBytes<UInt16>(LayerNum) as UInt16[];
}

int ind = 0;
for (int heigth = 0; heigth < bitmapHeigth; heigth++)
{
    for (int width = 0; width < bitmapWidth; width++)
    {
        int current = Convert.ToInt32(img.GetValue(ind));
        ind++;

        bmp.SetPixel(width, heigth, Color.FromArgb(current, current, current));
    }
}
pictureBox1.Image = bmp;
0
source share
1 answer

Quote from Hans Passant if someone is looking for an answer:

GDI + , - . . -, 16 24rgb. , 16- , , . , DICOM. , , Lead Tools.

0

All Articles