开发者

c++ gdi image array

im trying to make an array of images开发者_StackOverflow

Image something(L"something.png");

instead of that

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

any idea


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
   }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜