将用于绘制为位图的像素格式更改

Change pixel format for drawing into bitmap

本文关键字:像素 格式 位图 用于 绘制      更新时间:2023-10-16

我需要以位图像素为单位的交换RGBA通道。例如,.net图形将通道写入BGRA中的位图,我需要RGBA。我认为这个顺序是由像素格式描述符确定的,但我不知道如何。我确实喜欢

 PIXELFORMATDESCRIPTOR pfd = { 
            sizeof(PIXELFORMATDESCRIPTOR),   // size of this pfd  
            1,                     // version number  
            PFD_DRAW_TO_BITMAP |   // support window  
            PFD_SUPPORT_OPENGL | 
            PFD_NEED_PALETTE,       
            PFD_TYPE_COLORINDEX,         // RGBA type  
            32,                    // 24-bit color depth  
            8, 8, 8, 0, 0, 0,      // color bits ignored  
            8,                     // no alpha buffer  
            0,                     // shift bit ignored  
            0,                     // no accumulation buffer  
            0, 0, 0, 0,            // accum bits ignored  
            32,                    // 32-bit z-buffer  
            0,                     // no stencil buffer  
            0,                     // no auxiliary buffer  
            PFD_MAIN_PLANE,        // main layer  
            0,                     // reserved  
            0, 0, 0                // layer masks ignored  
        }; 

        int  iPixelFormat; 
  ::SelectObject ((HDC)_hdc.ToPointer (), (HBITMAP)_hBitmap.ToPointer ());
        iPixelFormat = ChoosePixelFormat((HDC)_hdc.ToPointer (), &pfd); 
    bool result = ::SetPixelFormat((HDC)_hdc.ToPointer (), iPixelFormat, &pfd);

我试图改变频道的转变,但它什么都不做。

由于您使用的是 .NET 和 Windows - 看看 Monogame 中的这段代码。它使用颜色矩阵来转置颜色分量。根据我的经验,这种方法快速、可靠且灵活。

对于您的特定问题,尽管看起来您需要一种方法将 VTK 提供的 RGBA 图像转换为位图采用的 BGRA。我在这里看到两个选项:

    要求VTK
  1. 渲染成BGRA位图(VTK中的某种SetPixelFormat调用?
  2. 使用在进行渲染时交换通道的像素着色器。这几乎没有任何相关成本,看起来您无论如何都在使用 OpenGL。

希望这有帮助!