如何使用 wxWidgets c++ 加载 gif
How to load gif using wxWidgets c++?
我需要你的帮助!我目前对wxWidgets非常陌生,作为一名大学生。我正在尝试使用 wxWidgets 加载.gif文件。我尝试使用以下代码...但它只加载 1 帧,它不会移动/更改为其他帧,它基本上是一张静止图片。该文件是扩展名.gif,它有 3 帧左右。图像的位置已经正确。帮助将不胜感激!
谢谢
#include "ImageWindow.h"
#include <wx/stdpaths.h>
#include <wx/filename.h>
BEGIN_EVENT_TABLE(ImageWindow, wxWindow)
EVT_PAINT(ImageWindow::OnPaint)
END_EVENT_TABLE()
ImageWindow::ImageWindow(wxFrame *parent)
: wxWindow(parent, wxID_ANY)
{
this->SetBackgroundColour(wxColour(*wxWHITE));
wxImageHandler *gifLoader = new wxGIFHandler();
wxImage::AddHandler(gifLoader);
this->LoadPotatoBitmap();
}
ImageWindow::~ImageWindow()
{
delete potatoBitmap;
}
void ImageWindow::LoadPotatoBitmap()
{
wxStandardPaths &stdPaths = wxStandardPaths::Get();
wxString fileLocation = stdPaths.GetExecutablePath();
wxImage image(wxT("A:\Projects\TestGif\Assets\Kuning.gif"),
wxBITMAP_TYPE_GIF);
potatoBitmap = new wxBitmap(image);
}
void ImageWindow::OnPaint(wxPaintEvent &event)
{
wxPaintDC pdc(this);
if (potatoBitmap != nullptr)
{
pdc.DrawBitmap(*potatoBitmap, wxPoint(150, 100), true);
}
}
您没有在构造函数中指定图像的索引,这就是为什么您看到默认索引的原因,如您在 wxWdigets 文档中看到的那样:
wxImage::wxImage ( const wxString & name,
wxBitmapType type = wxBITMAP_TYPE_ANY,
int index = -1
)
索引 在图像文件包含多个图像的情况下要加载的图像的索引。这仅由GIF,ICO和TIFF处理程序使用。默认值(-1(表示"选择默认图像",被GIF和TIFF处理程序解释为第一个图像(index=0(,被ICO处理程序解释为最大和最丰富多彩的图像。
但是,您还应该考虑 wxAnimationCtrl(请参阅此示例(
使用 wxAnimationCtrl 播放 gif 动画或
使用从 gif 图像中提取每一帧并使用 wxTimer 逐个绘制。
相关文章:
- std::原子加载和存储都需要吗
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 为什么加载SDF会导致Mobilizer创建闭环错误
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- 如何使用tinyxml2从XML加载父实体和子实体
- 如何在C++中使用pybind11加载一个pickle python列表
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- Python ctypes:不会按预期加载 dll
- 为什么会出现 gettnig 运行时错误:加载类型为"_Bit_type"(stl_bvector.h) 的空指针?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 保存/加载大量短数组到二进制文件
- 使用 SDL2 和SDL_image C++加载图像
- 无法使用加载库卸载注入的 dll (C++)
- 是否有原子加载非原子值的函数?
- 如何使用 wxWidgets c++ 加载 gif
- 如何最好地实现GIF加载类
- 直接X11加载GIF纹理