DicomImage::createWindowsDIB的用法
unsigned long DicomImage::createWindowsDIB | ( | void *& | data, |
const unsigned long | size, | ||
const unsigned long | frame = 0 , |
||
const int | bits = 24 , |
||
const int | upsideDown = 0 , |
||
const int | padding = 1 |
||
) | [inline] |
create true color (24/32 bit) or palette (8 bit) bitmap for MS Windows.
8 bit images require an appropriate color palette (256 entries, values: 0 to 255) and are only applicable to monochrome images, the beginning of a each line starts on a 32-bit address (if 'padding' is true); 24 bit images store 24 bits per pixel (RGB) and do align each line to a 32-bit address (if 'padding' is true); 32 bit images store 32 bits per pixel (RGB), but only use the upper 24 bits. The sample order for color images is (i.e. reverse): Blue, Green, Red. The memory buffer can be allocated both externally (from the calling program) and internally (inside this class/module). If the 'data' parameter is not NULL and the 'size' parameter, which describes the size (in bytes) of the allocated buffer, is suffiently large, the bitmap is stored in this buffer. Otherwise (i.e. 'data' is NULL) the memory is allocated internally. Please note that in both cases the memory is not handled internally after this method has finished and, therefore, must be deleted from the calling program. This method does not work if original YCbCr color model is retained (see CIF_KeepYCbCrColorModel).
- Parameters:
-
data untyped pointer memory buffer (set to NULL if not allocated externally) size size of the memory buffer in bytes (if 0 'data' is set to NULL) frame index of frame to be converted (default: 0 = first frame) bits number of bits per pixel used for the output bitmap (8, 24 or 32, default: 24) upsideDown flag indicating whether the first line stored is the top-most (default: 0) or the bottom-most of the source image (as required by the BMP file format) padding align each line to a 32-bit address if true (default)
- Returns:
- number of bytes allocated by the bitmap, or 0 if an error occured
这个函数生成DIB结构的数据区,不包括位图文件头(BITMAPFILEHEADER),位图信息头(BITMAPINFOHEADER),调色板(RGBQUAD[256])
data指向生成的数据区,若调用函数前,程序员为data分配了足够空间,则size为data的大小,DIB图像数据放在该空间内
若没有为data分配空间,size应设为0,在函数内部为data分配空间,并返回DIB图像数据的大小。
需要注意的是在这两种情况下,函数调用完后都没有释放data所指向的空间,需要程序员自己删除。
若想显示DIB位图有两种方法:
首先要生成DIB位图信息,
对于8位的DIB来说,需要添加位图信息头(BITMAPINFOHEADER),调色板(RGBQUAD[256])
在C*view::onDraw()中
用::StretchDIBits(pDC->GetSafeHdc(),
// destination rectangle
0,
0, 512, 512,
// source rectangle
0, 0, 512, 512,
((BYTE*)m_pImage+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)), //位图数据
(BITMAPINFO*)m_pImage, //位图信息
DIB_RGB_COLORS, SRCCOPY);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述