将用于绘制为位图的像素格式更改
Change pixel format for drawing into bitmap
我需要以位图像素为单位的交换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
- 渲染成BGRA位图(VTK中的某种SetPixelFormat调用?
- 使用在进行渲染时交换通道的像素着色器。这几乎没有任何相关成本,看起来您无论如何都在使用 OpenGL。
希望这有帮助!
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 为什么更改视频格式会更改其像素值?
- 使用C++解码为ffmpeg中的特定像素格式
- 图像的像素格式始终返回 32 位
- glew和glut您如何激活像素格式
- 未知像素格式错误SDL2
- 如何选择DirectX像素格式
- 如何使用 Windows API 获取像素格式布局
- OpenGL从4*浮点格式(C++)上传像素数据
- 通过 C/C++ 使用 JPEG 像素格式在 v4l2 中设置/获取相机 JPEG 压缩质量
- 将用于绘制为位图的像素格式更改
- 以在编译时和运行时都可用的方式描述C++像素格式信息
- 奇怪的SDL_Surface->格式->字节每像素值
- 如何在libavcodec中设置解码像素格式
- SDL2 纹理的像素格式和表面颜色遮罩
- 将 QImage 转换为YUV420P像素格式
- OpenGL上下文创建从不选择像素格式