【问题标题】:c++ gdi image arrayc++ gdi图像数组
【发布时间】:2010-08-31 04:54:25
【问题描述】:

我正在尝试制作一组​​图像

Image something(L"something.png");

而不是那个

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

任何想法

【问题讨论】:

    标签: c++ image winapi gdi+


    【解决方案1】:

    通过指针使用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
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 2014-07-11
      • 2011-02-21
      • 1970-01-01
      • 2018-12-25
      • 2014-03-16
      相关资源
      最近更新 更多