gpt4 book ai didi

c++ - 如何使用 wxWidgets C++ 加载 gif?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:07:34 25 4
gpt4 key购买 nike

我需要你的帮助!作为一名大学生,我目前对 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);
}
}

最佳答案

您没有在构造函数中指定图像的索引,这就是您看到默认索引的原因,正如您在 the wxWdigets documentation 中看到的那样。 :

wxImage::wxImage    (   const wxString &    name,
wxBitmapType type = wxBITMAP_TYPE_ANY,
int index = -1
)

index Index of the image to load in the case that the image file contains multiple images. This is only used by GIF, ICO and TIFF handlers. The default value (-1) means "choose the default image" and is interpreted as the first image (index=0) by the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.

但是,您还应该考虑 wxAnimationCtrl(参见 this sample)

关于c++ - 如何使用 wxWidgets C++ 加载 gif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47246198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com