Dave's Brain

Browse - programming tips - resource bitmap to gdi plus bitmap

Date: 2008jul12
Platform: GDI+
Language: C++

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());
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: