Exemplo n.º 1
0
        public override object Convert(object value, Type targetType, object parameter,
                                       System.Globalization.CultureInfo culture)
        {
            if (targetType != typeof(Object) && targetType != typeof(ImageSource))
            {
                throw new InvalidOperationException("The target must be Object or ImageSource !");
            }

            if (value == null)
            {
                return(null);
            }

            var         path        = value as string;
            ImageSource imageSource = AutoGreyableImage.GetSVGOrBitmapImageSource(path);

            return(imageSource);
        }
Exemplo n.º 2
0
        private void updateSource(AutoGreyableImage image, int size)
        {
            long zoomNormalized = (long)Math.Round(IconDrawScale * 1000);

            if (zoomNormalized == 1000)
            {
                image.LayoutTransform = null;
            }
            else
            {
                long scaleNormalized = (long)Math.Round(m_cachedScaleTransform.ScaleX * 1000);
                if (scaleNormalized != zoomNormalized)
                {
                    double inverseZoom = 1 / IconDrawScale;
                    m_cachedScaleTransform.ScaleX = inverseZoom;
                    m_cachedScaleTransform.ScaleY = inverseZoom;
                }
                image.LayoutTransform = m_cachedScaleTransform;
            }

            image.Width =
                (size == 0
                     ? Sizes.IconWidth_Small
                     : (size == 1
                            ? Sizes.IconWidth_Medium
                            : (size == 2 ? Sizes.IconWidth_Large : Sizes.IconWidth_XLarge)))
                * IconDrawScale;

            image.Height =
                (size == 0
                     ? Sizes.IconHeight_Small
                     : (size == 1
                            ? Sizes.IconHeight_Medium
                            : (size == 2 ? Sizes.IconHeight_Large : Sizes.IconHeight_XLarge)))
                * IconDrawScale;

            image.InitializeFromVectorGraphics(
                IconVisualBrush,
                image.Width, image.Height);

#if NET40
            if (false && image.CacheMode == null)
            {
                image.CacheMode = new BitmapCache
                {
                    RenderAtScale       = IconDrawScale,
                    EnableClearType     = false,
                    SnapsToDevicePixels = true
                };

                //var bitmapCacheBrush = new BitmapCacheBrush
                //{
                //    AutoLayoutContent = false,
                //    Target = image,
                //    BitmapCache = new BitmapCache
                //    {
                //        RenderAtScale = 0.3,
                //        EnableClearType = false,
                //        SnapsToDevicePixels = false
                //    }
                //};
                //var imageTooltip = new Canvas
                //{
                //    Width = image.Width * bitmapCacheBrush.BitmapCache.RenderAtScale,
                //    Height = image.Height * bitmapCacheBrush.BitmapCache.RenderAtScale,
                //    Background = bitmapCacheBrush
                //};
                //host.ToolTip = imageTooltip;
            }
#endif
        }
Exemplo n.º 3
0
        private AutoGreyableImage createImage(int size)
        {
            var image = new AutoGreyableImage
            {
                IsEnabled           = true,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,

                Stretch = Stretch.None, //Uniform

                Margin =
                    (size == 0
                         ? IconMargin_Small
                         : (size == 1
                                ? IconMargin_Medium
                                : (size == 2 ? IconMargin_Large : IconMargin_XLarge))),
            };

            updateSource(image, size);

            image.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified);
            //RenderOptions.SetEdgeMode(image, EdgeMode.Unspecified);

#if NET40
            image.SetValue(RenderOptions.ClearTypeHintProperty, ClearTypeHint.Auto);
            //RenderOptions.SetClearTypeHint(image, ClearTypeHint.Auto);

            image.CacheMode = null;
#endif //NET40

            image.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.LowQuality);
            //RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.LowQuality);

            image.SetValue(RenderOptions.CachingHintProperty, CachingHint.Cache);
            //RenderOptions.SetCachingHint(image, CachingHint.Cache);

            //image.SetValue(RenderOptions.CacheInvalidationThresholdMinimumProperty, 1);
            //image.SetValue(RenderOptions.CacheInvalidationThresholdMaximumProperty, 1);

            image.SnapsToDevicePixels = false;
            //image.SetValue(UIElement.SnapsToDevicePixelsProperty, false);



            return(image);


            //string sizeStr = (size == 0
            //                      ? "Small"
            //                      : (size == 1
            //                             ? "Medium"
            //                             : (size == 2 ? "Large" : "XLarge")));
            //var binding = new Binding
            //                  {
            //                      Mode = BindingMode.OneWay,
            //                      Source = this,
            //                      Path = new PropertyPath("Icon" + sizeStr),
            //                      Converter = new RenderTargetBitmapImageSourceConverter(),
            //                      ConverterParameter = false
            //                  };

            //var expr = image.SetBinding(Image.SourceProperty, binding);

            //Binding bind = cloneBinding(binding);
            //bind.ConverterParameter = true;
            //image.SourceBindingColor = binding;
            //image.SourceBindingGrey = bind;
        }