我正在应用程序中有一个conbobox和一个picturebox。用户选择一个路径,并且conbobox将路径加载到2000个图像,并显示第一个路径。当用户更改conbobox的索引时,显示的图像会发生变化,但我不知道如何删除图片框中的图像。Windows窗体 - 图片框。如何删除图像
如果我只是覆盖图像它没有做的工作,因为当我反复做这个程序崩溃,因为内存。如何删除图片框内的图片?
编辑: 我做了很少的变化,似乎无法再次重现错误..所以也许这是别的。但只是为了检查,这是代码泄漏的内存?
tips:config是一个单独的元素,包含一些信息,在这种情况下,图像在哪里。
private: System::Void comboBox_image1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
System::String^ aux;
DIC_config* config=DIC_config::Instance();
if(config->images_path!=NULL){
aux=gcnew System::String(config->images_path);
aux=aux+"\\CAM_0\\Snap_0_0"+(this->comboBox_image1->SelectedIndex+1)+".bmp";
System::IO::FileStream^ image_file=gcnew System::IO::FileStream(aux,System::IO::FileMode::Open,System::IO::FileAccess::Read);
System::Drawing::Bitmap^ img = gcnew System::Drawing::Bitmap(image_file);
this->pictureBox_image1->Image=img;
//img->~Bitmap(); this doesnt work, deletes the image of picturebox and makes the program chrash
}
}
你确定你有C++项目? – VladL 2013-03-11 09:44:09
我们已经在您的Sample中看到了C#代码...确认编程语言.... – Pandian 2013-03-11 09:50:17
@VladL对不起,刚刚从别处复制代码是因为我在编辑我的项目,但它并不完全正确。我有一个C++项目,不用担心。这个想法仍然是一样的。 – 2013-03-11 10:01:24