AdvancedLauncher.Tools.Imaging.IconHolder.GetImage C# (CSharp) Метод

GetImage() публичный Метод

public GetImage ( int code, bool webResource = true ) : BitmapImage
code int
webResource bool
Результат System.Windows.Media.Imaging.BitmapImage
        public BitmapImage GetImage(int code, bool webResource = true)
        {
            BitmapImage image = null;
            if (Dictionary.TryGetValue(code, out image)) {
                return image;
            }

            string resource = EnvironmentManager.ResolveResource(COMMUNITY_DIR,
                string.Format(PNG_FORMAT, code),
                string.Format(URLUtils.COMMUNITY_IMAGE_REMOTE_FORMAT, code));

            if (resource == null) {
                //If we don't have image yet, try to download it from joymax
                resource = EnvironmentManager.ResolveResource(COMMUNITY_DIR,
                    string.Format(PNG_FORMAT, code),
                    string.Format(IMAGES_REMOTE_JOYMAX, code));
            }

            if (resource == null) {
                //If we don't have image yet, try to download it from IMBC
                resource = EnvironmentManager.ResolveResource(COMMUNITY_DIR,
                    string.Format(PNG_FORMAT, code),
                    string.Format(IMAGES_REMOTE_IMBC, code));
            }

            if (resource != null) {
                Stream str = File.OpenRead(resource);
                if (str == null) {
                    return null;
                }
                MemoryStream img_stream = new MemoryStream();
                str.CopyTo(img_stream);
                str.Close();
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = img_stream;
                bitmap.EndInit();
                bitmap.Freeze();
                Dictionary.Add(code, bitmap);
                return bitmap;
            }
            return null;
        }
IconHolder