[英]How to reassign a wxImage pointer
I'm trying to create a kind of image editor in wxWidgets and I load and store the image in a wxImage pointer.我正在尝试在 wxWidgets 中创建一种图像编辑器,并将图像加载并存储在 wxImage 指针中。 As the user click a button it suppose to delete the pointer and assign them again to a new wxImage.
当用户单击一个按钮时,它会删除指针并将它们再次分配给一个新的 wxImage。 The code I use look like this.
我使用的代码如下所示。
class MyFrame : public wxFrame {
wxImage *old_image;
void OnLoad(wxCommandEvent &event);
};
void MyFrame::OnLoad(wxCommandEvent &event) {
// Get the image path with wxFileDialog and read it.
wxImage *new_image = new wxImage(new_width,
new_height,
image_data);
// old_image->Destroy(); // I think this also work
delete old_image;
old_image = new_image;
}
I know the code works the first time I load a new image, but by the second time it hangs and crash the application.我知道代码在我第一次加载新图像时有效,但到第二次它挂起并使应用程序崩溃。 So I think the error is not in the load algorithm.
所以我认为错误不在加载算法中。
How I suppose to delete the wxImage?我想如何删除 wxImage? Or there is a more reliable way to change the image?
还是有更可靠的方法来改变图像?
I'm using wxWidgets 3.0.5, MinGW-w64 with gcc 8.0.1我正在使用 wxWidgets 3.0.5、MinGW-w64 和 gcc 8.0.1
With that constructor, wxImage
will take ownership of image_data
and will free it when deleted.使用该构造函数,
wxImage
将获得image_data
的所有权,并在删除时释放它。 In order to reuse it, you must pass true
to the 4th argument ( static_data
, see the docs).为了重用它,您必须将
true
传递给第四个参数( static_data
,请参阅文档)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.