[英]Fill bitmap with 16 bit grayscale values without downscale
I have a file with raw image data. 我有一个包含原始图像数据的文件。 Every pixel is represented as
16 bit (0-65536)
value. 每个像素都表示为
16 bit (0-65536)
值。
I'm reading the needed part of data into an ushort[]
array. 我正在将所需的数据部分读取到
ushort[]
数组中。 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.
我绘制8位灰度没有问题(我只是将每个像素的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. 另一个可能性是使用
PixelFormat.Format48bppRgb
并将r,g和b设置为相同的16位grascale,但是我找不到方法。
I've found some code snippets using unsafe
code and LockBits
, but couldn't get them to work. 我发现了一些使用
unsafe
代码和LockBits
代码片段,但无法使它们正常工作。
Is there any way to draw the 16 bit grayscale image without to downscale it to 8 bit? 有什么方法可以绘制16位灰度图像而不将其缩小到8位?
Please provide me with a code snippet. 请向我提供一个代码段。
EDIT: this is how I set 8 bit grascales: 编辑:这就是我设置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;
Quote from Hans Passant in case somebody is looking for the answer : 如果有人正在寻找答案,请引用Hans Passant的话:
These pixel formats were defined in GDI+ with the expectation that someday it might be useful with sufficient advances in display technology.
这些像素格式是在GDI +中定义的,期望有朝一日,随着显示技术的充分发展,它可能会很有用。 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.
实际上,LCD面板无法以24rgb格式显示所有可能的1600万种颜色,因此发生了另一种变化。 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.
实际上,以16位格式查看灰度级需要专用的硬件和训练有素的眼睛,就像您在医院中看到的那样。 With a matching non-standard image format, like DICOM.
具有匹配的非标准图像格式,例如DICOM。 You can buy this from a vendor like Lead Tools.
您可以从诸如Lead Tools之类的供应商处购买。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.