【发布时间】:2017-11-12 06:41:30
【问题描述】:
我需要你的帮助!作为一名大学生,我目前对 wxWidgets 非常陌生。我正在尝试使用 wxWidgets 加载 .gif 文件。我尝试使用下面的代码......但它只加载一帧,它不会移动/更改为其他帧,它基本上是一张静止的图片。该文件是.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);
}
}
【问题讨论】:
-
static int GetImageCount (const wxString &filename, wxBitmapType type=wxBITMAP_TYPE_ANY)然后你必须手动绘制每一帧(图像)。