Пример #1
0
        public ImageResource GetImage(string fullPath)
        {
            ImageResource res = null;

            foreach (var i in images.Values)
            {
                if (i.FullPath != null && i.FullPath.ToLower().Equals(fullPath.ToLower()))
                {
                    res = i;
                    break;
                }
            }

            if (res != null)
            {
                if (res.Image != null)
                {
                    res.Image.Dispose();
                }
                res.Image = Image.FromFile(fullPath);
                return(res);
            }
            else
            {
                Image image;
                try
                {
                    image = Image.FromFile(fullPath);
                }
                catch (Exception ex)
                {
                    Logger.Log("resource pool", "add image file failed: " + ex.Message);
                    return(null);
                }

                return(AddImage(Guid.NewGuid(), image, fullPath));
            }
        }
Пример #2
0
        public ImageResource AddImage(Guid id, Image image, string fullPath)
        {
            ImageResource res;

            if (!images.TryGetValue(id, out res))
            {
                images.Add(id, res = new ImageResource()
                {
                    ResId    = id,
                    FullPath = fullPath,
                });

                Logger.Log("resource pool", "image added. count: " + images.Count);
            }

            if (res.Image != null)
            {
                res.Image.Dispose();
            }

            res.Image = image;

            return(res);
        }
Пример #3
0
        public ImageResource AddImage(Guid id, Image image, string fullPath)
        {
            ImageResource res;

            if (!images.TryGetValue(id, out res))
            {
                images.Add(id, res = new ImageResource()
                {
                    ResId = id,
                    FullPath = fullPath,
                });

                Logger.Log("resource pool", "image added. count: " + images.Count);
            }

            if (res.Image != null)
            {
                res.Image.Dispose();
            }

            res.Image = image;

            return res;
        }