在C#中我可以声明新的48bitRGB或64bitRGBA没有问题,实际上正确的格式保存在磁盘上.
但是,当声明颜色时,我无法声明超过8位值的颜色.这似乎是因为Color声明预计每个组件不超过8位.
我到目前为止的代码:
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
Run Code Online (Sandbox Code Playgroud)
在C#中声明16位颜色分量的方法是什么?
问题源于 Bitmap 类封装了 GDI+ bimap。
GDI+ 1.0 和 1.1 版可以读取每通道 16 位图像,但此类图像会转换为每通道 8 位格式以进行处理、显示和保存。关联
因此,当您设置像素值时,您正在处理每通道 8 位格式。
如果使用不安全代码,您可以直接访问这些值,请参阅获取 64bpp 图像颜色。