简体   繁体   中英

Bitmap creation in Win32 using Gdiplus

I'm trying to create a bitmap using Win32 and Gdiplus. I don't want to load in a file I just want to create my own image by using Setpixel. I used this constructor:

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

But when I try to use Setpixel on my bitmap it does nothing even GetHeight returns 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;

What am I doing wrong?

So I didn't know that I have to initialize Gdiplus first so that is what I was missing. And I changed the bitmap creation a bit. Now everything works.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM