使用Gdiplus在Win32中创建位图



我正在尝试使用Win32和Gdiplus创建位图。我不想加载到一个文件中,我只想通过使用Setpixel创建我自己的图像。我使用了这个构造函数:

void Bitmap(INT width, INT height, INT stride, PixelFormat format, BYTE *scan0);

但是当我尝试在位图上使用Setpixel时,它什么也不做,甚至GetHeight返回0。

m_pixelMap = new BYTE[m_renderSpaceWidth*m_renderSpaceHeight * 3];
Gdiplus::Bitmap img(m_renderSpaceWidth, m_renderSpaceHeight, 24 * m_renderSpaceWidth, PixelFormat24bppRGB, m_pixelMap);
std::cout << "H: " << img.GetHeight() << std::endl;

我做错了什么?

所以我不知道我必须首先初始化Gdiplus,所以这就是我所缺少的。我对位图的创建做了一些更改。现在一切正常。

m_stride =  ALIGN_CLUSPROP(3 * m_renderSpaceWidth);
m_padding = m_stride - (m_renderSpaceWidth * 3);
m_horizontalScanLine = (m_renderSpaceWidth * 3) + m_padding;
m_pixelMap = new BYTE[m_stride * m_renderSpaceHeight];
m_bitmap = new Gdiplus::Bitmap(m_renderSpaceWidth, m_renderSpaceHeight, m_stride, PixelFormat24bppRGB, m_pixelMap);

最新更新