Beispiel #1
0
        private static bool TryCreateImage(string base64, IEnumerable <string> imageBoxOverrides, out IControl result)
        {
            ImageBoxDescriptor imageBoxDescriptor = null;

            if (null != imageBoxOverrides)
            {
                foreach (var imageBoxId in imageBoxOverrides)
                {
                    if (CurrentConfig.ImageBoxDescriptors.TryGetValue(imageBoxId, out imageBoxDescriptor))
                    {
                        break;
                    }
                }
            }

            if (null == imageBoxDescriptor)
            {
                result = null;
                return(false);
            }

            var border = new Border()
            {
                Width  = imageBoxDescriptor.Width,
                Height = imageBoxDescriptor.Height,
            };

            if (AppVM.DebugMode)
            {
                border.Background = Brushes.Magenta;
            }

            Canvas.SetLeft(border, imageBoxDescriptor.X);
            Canvas.SetTop(border, imageBoxDescriptor.Y);

            try
            {
                var stream = Base64Utils.CreateStreamFromBase64(base64);

                Image image = new Image()
                {
                    Source  = new Bitmap(stream),
                    Width   = imageBoxDescriptor.Width,
                    Height  = imageBoxDescriptor.Height,
                    Stretch = Stretch.UniformToFill,
                };

                border.Child = image;
            }
            catch (Exception) { }

            result = border;
            return(true);
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is string base64)
     {
         try
         {
             var stream = Base64Utils.CreateStreamFromBase64(base64);
             return(new Bitmap(stream));
         }
         catch (Exception) { }
     }
     return(null);
 }