public static Image FromFileInc(String path) { String relativePath = UIProject.Instance().GetRelativePath(path); Image image = null; if (imageFactory.ContainsKey(relativePath)) { ImageInner inner = imageFactory[relativePath]; inner.count++; image = inner.image; } else { try { image = Image.FromFile(UIProject.Instance().GetRealFile(path)); } catch { image = null; } if (image != null) { imageFactory.Add(relativePath, new ImageInner(image, 1, relativePath)); } } return(image); }
public static void releaseImage(String path) { String relativePath = UIProject.Instance().GetRelativePath(path); if (imageFactory.ContainsKey(relativePath)) { ImageInner inner = imageFactory[relativePath]; if (--inner.count == 0) { inner.image.Dispose(); imageFactory.Remove(relativePath); } } }
public static void releaseImage(Image image) { foreach (String key in imageFactory.Keys) { ImageInner inner = imageFactory[key]; if (inner.image == image) { if (--inner.count == 0) { inner.image.Dispose(); imageFactory.Remove(key); break; } } } }