views:

32

answers:

2

im trying to make an array of images

Image something(L"something.png");

instead of that

Image something[2];
something[0]=(L"something.png");

any idea

A: 
Image something[2] = {Image(L"something.png"), Image(L"Something_else.png")};
Jerry Coffin
That won't work because the copy constructor in GdiPlus is private! It won't compile.
selbie
@selbie: That depends on the compiler and settings you use -- most allow the code since they'll optimize out actual use of the copy ctor. For example, even Comeau, about as standard-compliant as you can find, will accept the code unless you use `--A` (the "strict errors" mode).
Jerry Coffin
A: 

It's a lot easier to use Gdiplus image and bitmap objects by pointer.

Consider using an array of pointers. If you don't want to have to explicitly remember to free the array when you are done, you can use a smart pointer. In the code sample below I use CAutoPtr.

#include <Windows.h>
#include <gdiplus.h>
#include <atlbase.h>    

    void HandleImages(HDC hdc)
    {    
      typedef CAutoPtr<Gdiplus::Image> GdiplusImagePtr; // could be declared using CAutoPtr<Gdiplus::Bitmap>
      GdiplusImagePtr something[2];
      Gdiplus::Graphics g(hdc);

      something[0].Attach(new Gdiplus::Bitmap(L"something.png"));
      something[1].Attach(new Gdiplus::Bitmap(L"otherthing.png"));


      for (int x = 0; x < ARRAYSIZE(something); x++)
      {
          g.DrawImage(something[x], 50*x, 0);
      }

      // CAutoPtr will call destructor for each item in something array
   }
selbie