簡體   English   中英

使用 Gdiplus 在 Win32 中創建位圖

[英]Bitmap creation in Win32 using Gdiplus

我正在嘗試使用 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM