Dave's Brain

Browse - Programming Tips - How do I load a resource bitmap into a GDI+ bitmap?

Date: 2008jul12
Library: GDI+
Language: C/C++
OS: Windows

Q.  How do I load a resource bitmap into a GDI+ bitmap?

A.  Use this function:

Bitmap *ResourceToBitmap(const HINSTANCE hInstance, const int id) { HBITMAP hBmp = ::LoadBitmap(hInstance, MAKEINTRESOURCE(id)); if (bBmp == NULL) return NULL; return Bitmap::FromHBITMAP(hBmp, NULL); } void ExampleUse() { Bitmap *pBitmap; pBitmap = ResourceToBitmap(AfxGetInstanceHandle(), IDB_MY_BITMAP); printf("Size is %d x %d\n", pBitmap->GetWidth(), pBitmap->GetHeight()); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.