用 16 位灰度值填充位图,无需缩小 [英] Fill bitmap with 16 bit grayscale values without downscale

查看:25
本文介绍了用 16 位灰度值填充位图,无需缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含原始图像数据的文件.每个像素都表示为 16 位 (0-65536) 值.

I have a file with raw image data. Every pixel is represented as 16 bit (0-65536) value.

我正在将所需的数据部分读入 ushort[] 数组.在做了一些图像处理之后,我需要以某种方式向用户显示这个图像.我绘制 8 位灰度没有问题(我只是将每个像素的 R、G 和 B 值设置为相同),但无法处理 16 位/像素灰度图像.

I'm reading the needed part of data into an ushort[] array. After doing some image processing I need to show this image to the user somehow. I have no problem drawing an 8 bit grayscale (I just set every pixel's R, G and B values same), but can't handle 16 bit/pixel grayscale image.

另一种可能性是使用 PixelFormat.Format48bppRgb 并将 r、g 和 b 设置为相同的 16 位灰度,但我找不到方法.

Another possibilty is to use PixelFormat.Format48bppRgb and set r,g and b to the same 16 bit grascale, but I couldn't find how.

我发现了一些使用 unsafe 代码和 LockBits 的代码片段,但无法让它们工作.

I've found some code snippets using unsafe code and LockBits, but couldn't get them to work.

有没有办法绘制 16 位灰度图像而不将其缩小到 8 位?

Is there any way to draw the 16 bit grayscale image without to downscale it to 8 bit?

请给我一个代码片段.

这就是我设置 8 位灰度的方式:

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;

推荐答案

引用自 Hans Passant 以防有人正在寻找答案:

Quote from Hans Passant in case somebody is looking for the answer :

这些像素格式是在 GDI+ 中定义的,期望有一天它可能会在显示方面取得足够的进步技术.我们仍在等待.它实际上是另一个LCD面板无法显示所有可能的1600万的方式24rgb 格式的颜色.实际上看到一个灰度级16 位格式需要专门的硬件和训练有素的眼睛,你在医院里找到的那​​种.带有匹配的非标准图像格式,如 DICOM.您可以从 Lead Tools 等供应商处购买.

These pixel formats were defined in GDI+ with the expectation that someday it might be useful with sufficient advances in display technology. We are still waiting for that. It actually went the other way with LCD panels not being able to display all possible 16 million colors from a 24rgb format. Actually seeing the gray levels in a 16-bit format requires specialized hardware and a highly trained eye, the kind you find in a hospital. With a matching non-standard image format, like DICOM. You can buy this from a vendor like Lead Tools.

这篇关于用 16 位灰度值填充位图,无需缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆