コード例 #1
0
ファイル: SvgHelper.cs プロジェクト: ragnakuei/WpfSample01
        public static ImageSource FromFilePathToImageSource(string svgFilePath)
        {
            var svgStream = File.Open(svgFilePath, FileMode.Open, FileAccess.Read);
            var svgImage  = SvgLoader.LoadFromStream(svgStream);
            var size      = new Size(svgImage.Width * ScreenHelper.ScaleX, svgImage.Height * ScreenHelper.ScaleX);

            return(WpfSvgRenderer.CreateImageSource(svgImage, size, null, null, true));
        }
コード例 #2
0
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var uri = uriConverter.ConvertFrom(value) as Uri;

            if (uri == null)
            {
                return(DependencyProperty.UnsetValue);
            }

            var absoluteUri = uri.IsAbsoluteUri ? uri : new Uri(baseUri, uri);

            using (var stream = GetStream(absoluteUri))
            {
                var image = SvgLoader.LoadFromStream(stream);
                return(WpfSvgRenderer.CreateImageSource(image, 1d, null, null, true));
            }
        }