Esempio n. 1
0
        /// <summary>
        /// Gets the cached bitmap image representing the card object. Will query the API if it has not been loaded, otherwise gets the cached version.
        /// </summary>
        public static async Task <Bitmap> GetImageAsync(string imageUri, IProgress <string> reporter)
        {
            if (string.IsNullOrWhiteSpace(imageUri))
            {
                throw new ArgumentNullException(nameof(imageUri), @"Image request URI cannot be null or empty/whitespace. Consumer must check before using this method.");
            }

            while (IsCacheBeingAccessed)
            {
                await Task.Delay(1);
            }

            IsCacheBeingAccessed = true;

            if (ImageCache.ContainsKey(imageUri))
            {
                await Task.Delay(1);

                IsCacheBeingAccessed = false;
                return(ImageCache[imageUri]);
            }

            Bitmap bitmap = await ScryfallService.GetImageAsync(imageUri, reporter);

            ImageCache.Add(imageUri, bitmap);

            if (ImageCache.Count > 100)
            {
                ImageCache.Remove(ImageCache.First().Key);
            }

            IsCacheBeingAccessed = false;
            return(bitmap);
        }
Esempio n. 2
0
        public void Image(string name, Stream stream, float x, float y, float width = 0, float height = 0)
        {
            System.Drawing.Image img = null;
            if (!ImageCache.TryGetValue(name, out img))
            {
                img = System.Drawing.Image.FromStream(stream);
                var bitmap = new Bitmap(img);
                bitmap.MakeTransparent(bitmap.GetPixel(0, 0));
                ImageCache.Add(name, bitmap);
            }

            float sx      = x;
            float sy      = y;
            float swidth  = width == 0 ? img.Width : width;
            float sheight = height == 0 ? img.Height : height;
            float sother  = 0;

            if (Translate != null && DoTranslation && !Translate(DoScaling, x, y, swidth, sheight, 0, out sx, out sy, out swidth, out sheight, out sother))
            {
                return;
            }

            // safe guard accidental usage
            x = y = 0;

            // use screen coordinates
            Graphics.DrawImage(img, sx, sy, swidth, sheight);
        }
Esempio n. 3
0
 private void SaveToImageCache(string document, IServerProcess process, IScalar LResult)
 {
     lock (ImageCache)
     {
         byte[] value = null;
         if ((LResult != null) && (!LResult.IsNil))
         {
             value = LResult.AsByteArray;
         }
         ImageCache.Add(document, value);
     }
 }
        public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            // Get the set of serializable members for our class and base classes
            Type thisType = obj.GetType();

            MemberInfo[] mi = FormatterServices.GetSerializableMembers(thisType, context);

            System.Drawing.Image        image    = null;
            List <object>               dataList = new List <object>();
            SerializationInfoEnumerator sie      = info.GetEnumerator();

            while (sie.MoveNext())
            {
                object val = sie.Current.Value;
                if (sie.Name == "icon")
                {
                    image = val as System.Drawing.Image;
                    val   = null;
                }
                dataList.Add(val);
            }
            object[] data = dataList.ToArray();
            obj = FormatterServices.PopulateObjectMembers(obj, mi, data);

            // handle the icon
            if (image != null)
            {
                RegisteredApplication ra = obj as RegisteredApplication;
                if (ra != null)
                {
                    ra.IconID = ImageCache.Add(ra.Name, image);
                    image.Dispose();
                    image = null;
                }
                else
                {
                    RegisteredNotification rn = obj as RegisteredNotification;
                    if (rn != null)
                    {
                        AddTemporaryNotificationImage(rn, image);
                        // dont dispose of the image yet, it will get taken care of later
                    }
                }
            }

            return(obj);
        }
        public Texture GetImage(string url)
        {
            Texture texture;

            if (ImageCache.TryGetValue(url, out texture))
            {
                return(texture ?? ElementDesignerStyles.GetSkinTexture("LoadingImage"));
            }
            ImageCache.Add(url, null);
            DownloadImage(url);
            if (ImageCache.TryGetValue(url, out texture))
            {
                return(texture ?? ElementDesignerStyles.GetSkinTexture("LoadingImage"));
            }
            else
            {
                return(ElementDesignerStyles.GetSkinTexture("LoadingImage"));
            }

            //return ElementDesignerStyles.ArrowDownTexture;
        }
Esempio n. 6
0
        private Image GetMapImage(string name)
        {
            Image result;

            if (ImageCache == null)
            {
                ImageCache = new Dictionary <string, Image>();
            }

            if (!ImageCache.TryGetValue(name, out result))
            {
                //this.SetStatus("Loading image...");

                result = Image.FromFile(GetMapFileName(name));

                ImageCache.Add(name, result);

                //this.SetStatus(string.Empty);
            }

            //this.SetMessage(string.Format("Switching to image {0}.jpg", name));

            return(result);
        }