首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >c++ gdi图像数组

c++ gdi图像数组
EN

Stack Overflow用户
提问于 2010-08-31 12:54:25
回答 1查看 1.2K关注 0票数 1

我正在尝试制作一个图像数组

代码语言:javascript
运行
复制
Image something(L"something.png");

而不是那样

代码语言:javascript
运行
复制
Image something[2];
something[0]=(L"something.png");

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-31 13:17:14

通过指针使用Gdiplus图像和位图对象要容易得多。

考虑使用指针数组。如果您不想在完成时显式地记住释放数组,则可以使用智能指针。在下面的代码示例中,我使用了CAutoPtr。

代码语言:javascript
运行
复制
#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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3606126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档