C# 64位图像颜色声明(每个通道16位)

C# 64位图像颜色声明(每个通道16位),c#,image,colors,C#,Image,Colors,在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 wi

在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
intx;
int-y;
int w=512,h=512;
位图图像=新位图(w、h、System.Drawing.Imaging.PixelFormat.Format48bppRgb)//每个通道16位的新图像,没有问题
//双“for”控制结构在整个图像上逐像素移动
对于(y=0;ySystem.Drawing.Color newColor=System.Drawing.Color.FromArgb(255,comp,comp,comp);//问题源于位图类封装GDI+bimap的事实

GDI+版本1.0和1.1可以读取每通道16位的图像,但这些图像被转换为每通道8位的格式,用于处理、显示和保存

因此,当您设置像素值时,您正在处理每通道8位格式


如果使用不安全代码,您可以直接访问值,请参见。

您可以访问原始像素,请参见此处:System.Drawing.Color内部如何使用长(带符号的64位整数)要表示它的RGBA值,但它的所有操作都接受整数,您需要创建自己的位图类或使用等效的图形格式库。是的,我使用的是WPF,为什么?我试图避免直接访问,但似乎没有更好的方法。非常感谢!您可以通过复制整个备份阵列来避免不安全的代码(或其中的一部分,取决于您的操作)退出图像,并在处理后使用
marshall.Copy