public void Dispose() { if (this.image != null) { ImageCache.releaseImage(image); this.image.Dispose(); } this.image = null; GC.SuppressFinalize(this); }
/// <summary> /// releases the image from memory and file. To get it back use ensureImageExists() /// </summary> public void releaseImage() { if (imageDisposable) { if (this.image != null && ImageCache.releaseImage(image)) { this.image.Dispose(); // only local images are disposed, those from image cache will stay there. } this.image = null; } GC.Collect(); }
/// <summary> /// delete image file inside the zip file, or return a name of file to delete on the hard drive. /// Make sure you dispose of this PhotoDescr before deleting the file. /// </summary> public string deleteFromDisk() { string ret = null; if (this.imageSourceIsLocal) { // make sure the image is not used/locked and we can actually delete it: releaseImage(); ImageCache.releaseImage(m_imageFileName); GC.Collect(); int pos = m_imageFileName.IndexOf("|"); if (pos >= 0) { // this is a .zip or .gpz file string zipFileName = m_imageFileName.Substring(0, pos); if (!File.Exists(zipFileName)) { LibSys.StatusBar.Error("Failed to open Zip"); throw new InvalidOperationException("'" + zipFileName + "' not found or not a valid zip file"); } using (ZipFile zip = new ZipFile(zipFileName)) { string photoFileName = m_imageFileName.Substring(pos + 1); ZipEntry zipEntry = zip.GetEntry(photoFileName); if (zipEntry != null) { zip.BeginUpdate(); zip.Delete(zipEntry); } else { zip.Close(); throw new InvalidOperationException("'" + photoFileName + "' is not found inside " + zipFileName); } zip.CommitUpdate(); } } else { ret = m_imageFileName; } } return(ret); }