C# devexpress galleryControl 在加载图片后 删除图片被占用问题

以官方例子为例

GalleryControl gc = new GalleryControl();
gc.Dock = DockStyle.Fill;
this.Controls.Add(gc);
   问题出处代码
Image im1 = Image.FromFile("c:\\Images\\BMW.jpg");
Image im2 = Image.FromFile("c:\\Images\\Ford.jpg");
Image im3 = Image.FromFile("c:\\Images\\MercedecBenz.jpg");
Image im4 = Image.FromFile("c:\\Images\\AnneDodsworth.jpg");
Image im5 = Image.FromFile("c:\\Images\\HannaMoos.jpg");
Image im6 = Image.FromFile("c:\\Images\\JanetLeverling.jpg");

  以上六行为问题出处代码

gc.Gallery.ItemImageLayout = ImageLayoutMode.ZoomInside;
gc.Gallery.ImageSize = new Size(120, 90);
gc.Gallery.ShowItemText = true;

GalleryItemGroup group1 = new GalleryItemGroup();
group1.Caption = "Cars";
gc.Gallery.Groups.Add(group1);

GalleryItemGroup group2 = new GalleryItemGroup();
group2.Caption = "People";
gc.Gallery.Groups.Add(group2);

group1.Items.Add(new GalleryItem(im1, "BMW", ""));
group1.Items.Add(new GalleryItem(im2, "Ford", ""));
group1.Items.Add(new GalleryItem(im3, "Mercedec-Benz", ""));

group2.Items.Add(new GalleryItem(im4, "Anne Dodsworth", ""));
group2.Items.Add(new GalleryItem(im5, "Hanna Moos", ""));
group2.Items.Add(new GalleryItem(im6, "Janet Leverling", ""));

  

问题出在标注代码处,Image 占用了图片,建议修改为文件流打开文件生成image

FileStream fs1 = new System.IO.FileStream(path, FileMode.Open, FileAccess.Read);
 Image image = System.Drawing.Image.FromStream(fs1);
 fs1.Close();
 fs1.Dispose();

  

删除组或者图片后不再占用

posted @ 2021-04-14 15:34  静下心来邹  阅读(206)  评论(0编辑  收藏  举报