开发者

Creating an HICON from a byte array in C++?

开发者 https://www.devze.com 2022-12-14 11:55 出处:网络
I have a PNG-encoded icon as a byte array in memory. What is the recommended way of creating an HICON object from this byte array?

I have a PNG-encoded icon as a byte array in memory. What is the recommended way of creating an HICON object from this byte array?


Imaginary bonus points if you know a solution without ATL o开发者_运维知识库r GDI+... :)


HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, dataSize);
LPVOID pImage = GlobalLock(hMem);
memcpy(pImage, pngData, dataSize);
GlobalUnlock(hMem);

ATL::CComPtr<IStream> pStream;
CreateStreamOnHGlobal(hMem, TRUE, &pStream);

Gdiplus::Bitmap *pBitmap = new Gdiplus::Bitmap(pStream);
HICON YOUR_HICON = pBitmap->GetHICON();


It looks like you could do this with CreateBitmap and CreateIconIndirect, or maybe even just CreateIcon. Don't ask me for code because I'm not really familiar with this low-level graphics stuff.

0

精彩评论

暂无评论...
验证码 换一张
取 消