Created
September 27, 2021 15:18
-
-
Save Tocchann/6f656dfe25d13c33673d372a65d274f9 to your computer and use it in GitHub Desktop.
リソースに格納したPNGをGDI+でロードする(エラーチェックなし版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// リソースファイル上はこんな感じで格納 | |
// #define IDB_PNG 12345 | |
// IDB_PNG PNG "res\\png.png" | |
Gdiplus::Bitmap* LoadPngFromResource( HINSTANCE hInst, UINT resID ) | |
{ | |
HRSRC hResInfo = FindResource( hInst, MAKEINTRESOURCE(resID), _T("PNG") ); | |
HGLOBAL hResImage = LoadResource( hModule, hResInfo ); | |
DWORD size = SizeofResource( hModule, hResInfo ); | |
const BYTE* srcImage = static_cast<const BYTE*>( LockResource( hResImage ) ); | |
IStreamPtr ptrStream( SHCreateMemStream( srcImage, size ) ); | |
return new Gdiplus::Bitmap( ptrStream ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#include <comdef.h> が必要(IStreamPtrのため)なのを忘れているw