Пример #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value?.GetType() != typeof(ImageFile))
            {
                return(null);
            }

            ImageFile imgFile = (ImageFile)value;

            var tmp = ImageConverter.Convert(imgFile.GetData(), imgFile.Format, imgFile.Width, imgFile.Height);

            BitmapImage result;

            using (var ms = new MemoryStream())
            {
                tmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ms.Position = 0;

                result = new BitmapImage();
                result.BeginInit();
                result.CacheOption  = BitmapCacheOption.OnLoad;
                result.StreamSource = ms;
                result.EndInit();
            }

            return(result);
        }
Пример #2
0
//        public event PropertyChangedEventHandler PropertyChanged;
//
//        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
//        {
//            add => throw new NotImplementedException();
//            remove => throw new NotImplementedException();
//        }

        private void LoadIcons()
        {
            var realm  = new ARealmReversed(Properties.Settings.Default.GamePath, Language.English);
            var micons = realm.GameData.GetSheet("MacroIcon");

            _iconImages = new Dictionary <string, BitmapImage>();

            foreach (var row in micons)
            {
                string key = $"{(int)row.GetRaw(0):X7}";
                if (key == "0000000")
                {
                    continue;
                }
                ImageFile imgFile = IconHelper.GetIcon(row.Sheet.Collection.PackCollection, SaintCoinach.Ex.Language.English, (int)row.GetRaw(0));
                var       tmp     = ImageConverter.Convert(imgFile.GetData(), ImageFormat.A8R8G8B8_1, imgFile.Width, imgFile.Height);

                using (var ms = new MemoryStream())
                {
                    tmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ms.Position = 0;

                    var bi = new BitmapImage();
                    bi.BeginInit();
                    bi.CacheOption  = BitmapCacheOption.OnLoad;
                    bi.StreamSource = ms;
                    bi.EndInit();

                    if (!_iconImages.ContainsKey(key))
                    {
                        _iconImages.Add(key, bi);
                    }
                }
            }
        }