Create and array of Bitmaps using GDI+

Create and array of Bitmaps using GDI+

Post by RVdPbHNvb » Sun, 12 Jul 2009 08:08:06


Sorry if this is the wrong area, but I'm not sure where to post this.

I've figured out how to create images (bitmaps) with GDI+, and am very happy
with the results. I just need to be able to create an array of said bitmaps
so I can reference them by an index instead of having to type an entire
variable name.

An example of the kind of code I'm using now is:

HDC hdc = GetDC(hWnd);
Gdiplus::Graphics graphics(hdc);

Gdiplus::Bitmap bitmap1(L"1.png");
Gdiplus::Bitmap bitmap2(L"2.png");
Gdiplus::Bitmap bitmap3(L"3.png");
Gdiplus::Bitmap bitmap4(L"4.png");
Gdiplus::Bitmap bitmap5(L"5.png");
Gdiplus::Bitmap bitmap6(L"6.png");
Gdiplus::Bitmap bitmap7(L"7.png");
Gdiplus::Bitmap bitmap8(L"8.png");

ReleaseDC(hWnd, hdc);

and what I want is something along the lines of:

HDC hdc = GetDC(hWnd);
Gdiplus::Graphics graphics(hdc);

Gdiplus::Bitmap bitmap[8];

bitmap[0] = (L"1.png");
bitmap[1] = (L"2.png");
bitmap[2] = (L"3.png");
bitmap[3] = (L"4.png");
bitmap[4] = (L"5.png");
bitmap[5] = (L"6.png");
bitmap[6] = (L"7.png");
bitmap[7] = (L"8.png");

ReleaseDC(hWnd, hdc);

I know that isn't the right syntax. That's what I need help with.

I'm assuming there is a way to do this. Does anyone know how?

Thanks in advance for any assistance you could give me.
 
 
 

Create and array of Bitmaps using GDI+

Post by ZHJqYXNvbm » Wed, 15 Jul 2009 01:12:01

You want and array of pointers, and to call new to allocate the bitmaps and
call their constructor:

Gdiplus::Bitmap * bitmap[8];
bitmap[0] = new Gdiplus::Bitmap(L"1.png");
bitmap[1] = new Gdiplus::Bitmap(L"2.png");


some time later, you will want to call:

delete bitmap[0];
delete bitmap[1];
....

-Jason