2010-08-31 89 views
1

IM試圖使圖像C++ GDI圖像陣列

Image something(L"something.png"); 

的而不是

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

數組任何想法

回答

0

這是一個更容易通過使用Gdiplus圖像和位圖對象指針。請考慮使用指針數組。如果您不想在完成時明確記住釋放陣列,則可以使用智能指針。在下面的代碼示例中,我使用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 
    }