图像绘制在48bpp类型的c#中 [英] Image Draw in c# of type 48bpp

查看:126
本文介绍了图像绘制在48bpp类型的c#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制48bppRBG像素格式的 灰度 图像。

我有一个ushort值的数组/列表。这些值是像素值。因此每种颜色(R,G和B)将具有相同的像素值,因为它是灰度图像。在24bpp类型中,扫描这些值然后转换为< b>字节< / b>然后分配到位图图像。



我的问题是如何扫描这些值(使用Scan0和Stride),类型为ushort,并绘制48bppRBG的图像?

I'm trying to draw a grayscales image of type 48bppRBG pixel format.
I have an array/list of ushort values. These values are the pixels values. So each color(R, G ans B) will have the same pixel value, since it's a grayscale image. In an 24bpp type, these values are scanned then converted to <b>byte </b> then assigned to the bitmap image.

My question is how can I scan these values (using Scan0 and Stride), of type ushort,and draw an image of 48bppRBG?

推荐答案

首先是一些背景:



您写道:



在24bpp类型中,扫描这些值然后转换为字节然后分配给位图图像。



我在之前的工作中看到的每台扫描仪,包括佳能,惠普,柯尼卡美能达,东芝等的扫描仪,所有扫描的彩色图像随后都转换为灰度调色板的灰度图像。



转换为:



GrayColor = 0.299红色+ 0.587绿色+ 0.114蓝色。



(注意0.299 + 0.587 + 0.114)加起来为1.0)。



对于BMP图像格式,GrayColor值将用于索引到与BMP图像格式相关联的调色板中这里调色板中的每个(RGB)颜色具有相同的R,G和B值,并且特定索引处的每个值都与索引的值相同。



换句话说,灰度实现为带有调色板的彩色图像,调色板中的所有颜色都是灰度颜色。按顺序和跳过大多数中心颜色的颜色是(0,0,0),(1,1,1),(2,2,2,...),......(254,254,254),( 255,255,255)。



--------------------------- ---------------------------------



In在您摆出的情况下,您可以创建一个BMP图像,其调色板具有65536个RGB条目,范围从(0,0,0)到(65535,65535,65535)。然后每个颜色条目将是调色板中的16位索引。 Microsoft支持此图像格式。我不知道C#是否支持这种功能,但很容易检查它。



.NET 4.5(和早期版本?)提供了一种简单的方法制作16位调色板 - 请参阅:



http://msdn.microsoft.com/en-us/library/system.drawing.graphics.gethalftonepalette% 28v = vs.110%29.aspx



但是,无论来源如何,WPF都只会显示0到255范围内的值。因此,您可以以高分辨率存储图像数据,但我不知道如何以全亮度分辨率查看图像。



与Bill Woodruff一样,我提出质疑在图像中需要那么多的亮度精度。扫描仪中最先进的传感器通常产生12位或更低的色彩精度,因此16位可能是过度杀伤。大多数显示器不允许渲染如此精细的阴影差异,即使他们这样做,我也不认为调色板中的相邻颜色会与人眼有明显不同。但是,你的情况可能是独一无二的 - 但如果不是这样的话,我会选择一个8位的调色图像 - 这种格式会占用更少的空间。





要编写所需的代码,请找到标准的8位灰度情况并将值转换为16位。调色板将从256个32位RGB值(一个字节未使用)变为65536个32位RGB值的调色板。 (调色板条目在BMP图像格式中始终为32位 - 最重要的字节可以设置为0 - 或忽略。然后将字节值更改为短值并相应地调整所有循环索引。我希望这有帮助。
First some background:

You wrote:

"In an 24bpp type, these values are scanned then converted to byte then assigned to the bitmap image."

Every scanner I have seen in a previous job, which included scanners by Canon, HP, Konica Minolta, Toshiba, and more, all scanned color images that were subsequently converted to grayscale images with a grayscale palette.

The conversion is:

GrayColor = 0.299 Red + 0.587 Green + 0.114 Blue.

(Note that 0.299 + 0.587 + 0.114) add up to 1.0).

For the BMP image format, the GrayColor value would be used an index into a color palette associated with the BMP image format, where each (RGB) color in the palette has the same R, G, and B value, and each of these values at a particular index is the same value as the index.

In other words, Grayscale is implemented as a color image with a color palette, just all the colors in the palette are grayscale colors. The colors, in order, and skipping most central colors, are (0, 0, 0), (1, 1, 1), (2, 2, 2,), ... (254, 254, 254), (255, 255, 255).

------------------------------------------------------------

In the case you pose, you can create a BMP image with a palette that has 65536 RGB entries that range from (0, 0, 0) to (65535, 65535, 65535). Then each color entry would be a 16-bit index into the palette. Microsoft supports this image format. I don't know if this is supported in C#, but it would be easy to check that.

.NET 4.5 (and earlier versions?) provides an easy way to make a 16-bit palette - see:

http://msdn.microsoft.com/en-us/library/system.drawing.graphics.gethalftonepalette%28v=vs.110%29.aspx

However, WPF will only display values in the range of 0 to 255 regardless of the source. So, you can store the image data in high-resolution, but I do not know how to view the image at full luminance resolution.

Like Bill Woodruff, I question the need for that amount of luminance precision in an image. Most advanced sensors in scanners typically produce 12-bits or less of color accuracy, so 16 bits is probably overkill. Most displays don't allows rendering such fine shade differences, and even if they did, I don't think adjacent colors in the palette would be discernably different to the human eye. However, your case might be unique - but if it isn't, I'd go with an 8-bit palettized image - that format takes up a lot less space.


To write the code you want, find the standard 8-bit grayscale case and convert the values to 16-bit. The palette will go from being 256 32-bit RGB values (one byte is unused) to a palette of 65536 32-bit RGB values. (Palette entries are always 32-bit in the BMP image format - the most significant byte can be set to 0 - or ignored. Then change the byte value to be short values and adjust all the loop indexing accordingly. I hope that helps.


提到的32位条目用于带调色板的图像的pallete条目。



因为你指定了Red,Green ,对于每个像素分别为蓝色,你不需要托盘。



我不知道是否是BMP格式,这是一种文件格式(BITMAPINFO结构)在C ++中)支持每像素超过32位。如果C#具有PixelFormat.Format48bppRgb格式,那么它必须支持该图像格式 - 这可能适用于使用每个颜色分量超过8位的现代相机拍摄的图像。 br />


然而,WPF和绝大多数显卡(全部都是?)不支持超过16,777,216种颜色,即24位颜色,8-位颜色组件。



------------------------------------ -------



我有一个问题要问你。你陈述了你想要做的事情,但你没有说明什么是无效的。有什么显示?程序崩溃了吗?会发生什么?



您是否尝试过Bill Woodruff的消息中的链接?
The 32-bit entries mentioned are for pallete entries for images that take a palette.

Because you are specifying Red, Green, and Blue separately for each pixel, you don't need a pallete.

I don't know if the BMP format, which is a file format (BITMAPINFO structure in C++) supports more than 32 bits-per-pixel. If C# has a PixelFormat.Format48bppRgb format, then it must support that image format - this is probably for images taken with modern cameras that have more than 8 bits per color component.

However, WPF, and the vast majority of graphics cards (all of them?) don't support more than 16,777,216 colors, that is 24-bit color with 8-bit color components.

-------------------------------------------

I have a question for you. You stated what you are trying to do, but you didn't state what wasn't working. Does anything display? Does the program crash? What happens?

Did you try what is at the link in Bill Woodruff's message?


这篇关于图像绘制在48bpp类型的c#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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