Skip to content

Instantly share code, notes, and snippets.

@Tocchann
Created September 27, 2021 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tocchann/6f656dfe25d13c33673d372a65d274f9 to your computer and use it in GitHub Desktop.
Save Tocchann/6f656dfe25d13c33673d372a65d274f9 to your computer and use it in GitHub Desktop.
リソースに格納したPNGをGDI+でロードする(エラーチェックなし版)
// リソースファイル上はこんな感じで格納
// #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 );
}
@Tocchann
Copy link
Author

#include <comdef.h> が必要(IStreamPtrのため)なのを忘れているw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment