c++ gdi图像数组

发布于 2024-09-16 14:27:16 字数 181 浏览 2 评论 0原文

我试图制作一组图像

Image something(L"something.png");

而不是

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

任何想法

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-09-23 14:27:16

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

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
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文