コード例 #1
0
        public static ImageSource CreateSvgImage(string relativePath)
        {
            var uri       = new Uri($"pack://application:,,,/{relativePath}", UriKind.Absolute);
            var svgHelper = SvgImageHelper.CreateImage(uri);

            return(WpfSvgRenderer.CreateImageSource(svgHelper, 1d, null, null, true));
        }
コード例 #2
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));
        }
コード例 #3
0
        /// <summary>
        /// Converts Svg bytes to ImageSource
        /// </summary>
        /// <param name="path"></param>
        /// <returns>a usable <see cref="ImageSource"/></returns>
        public static ImageSource ToImageSource(Uri path)
        {
            using var stream = SvgImageHelper.CreateStream(path);
            object unused = null;
            var    image  = SvgImageHelper.GetOrCreateSvgImage(stream, ref unused);

            return(WpfSvgRenderer.CreateImageSource(image, 1d, null, null, true));
        }
コード例 #4
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var uri = uriConverter.ConvertFrom(value) as Uri;

            if (uri == null)
            {
                return(null);
            }
            var absoluteUri = uri.IsAbsoluteUri ? uri : new Uri(baseUri, uri);

            return(WpfSvgRenderer.CreateImageSource(absoluteUri));
        }
コード例 #5
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));
            }
        }