Load() public static method

Loads an SVG document and renders it into a DrawingImage.
public static Load ( Stream stream ) : System.Windows.Media.DrawingImage
stream System.IO.Stream /// A to read the XML structure of the SVG /// document. ///
return System.Windows.Media.DrawingImage
示例#1
0
        //==========================================================================
        /// <summary>
        ///   Overrides <see cref="MarkupExtension.ProvideValue"/> and returns the
        ///   <see cref="DrawingImage"/> the SVG document is rendered into.
        /// </summary>
        /// <param name="serviceProvider">
        ///   Object that can provide services for the markup extension;
        ///   <paramref name="serviceProvider"/> is not used.
        /// </param>
        /// <returns>
        ///   The <see cref="DrawingImage"/> the SVG image is rendered into or
        ///   <c>null</c> in case there has been an error while parsing or
        ///   rendering.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            try
            {
                using (Stream stream = Application.GetResourceStream(m_Uri).Stream)
                    return(SvgReader.Load(new GZipStream(stream, System.IO.Compression.CompressionMode.Decompress), new SvgReaderOptions {
                        IgnoreEffects = m_IgnoreEffects
                    }));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.GetType() + ": " + exception.Message);
            }

            try
            {
                using (Stream stream = Application.GetResourceStream(m_Uri).Stream)
                    return(SvgReader.Load(stream, new SvgReaderOptions {
                        IgnoreEffects = m_IgnoreEffects
                    }));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.GetType() + ": " + exception.Message);
                return(null);
            }
        }
示例#2
0
        //==========================================================================
        public override Drawing GetBaseDrawing()
        {
            if (Data == null)
            {
                return(null);
            }
            ImageSource imageSource = null;

            switch (DataType)
            {
            case "jpeg":
            case "png":
                var bmp = new BitmapImage();
                bmp.BeginInit();
                bmp.StreamSource = new MemoryStream(Data);
                bmp.EndInit();
                imageSource = bmp;
                break;

            case "svg+xml":
                imageSource = SvgReader.Load(new MemoryStream(Data));
                break;
            }
            if (imageSource == null)
            {
                return(null);
            }
            return(new ImageDrawing(imageSource, new Rect(
                                        new Point(X.ToDouble(), Y.ToDouble()),
                                        new Size(Width.ToDouble(), Height.ToDouble())
                                        )));
        }
示例#3
0
        //==========================================================================
        /// <summary>
        ///   Overrides <see cref="MarkupExtension.ProvideValue"/> and returns the
        ///   <see cref="DrawingImage"/> the SVG document is rendered into.
        /// </summary>
        /// <param name="serviceProvider">
        ///   Object that can provide services for the markup extension;
        ///   <paramref name="serviceProvider"/> is not used.
        /// </param>
        /// <returns>
        ///   The <see cref="DrawingImage"/> the SVG image is rendered into or
        ///   <c>null</c> in case there has been an error while parsing or
        ///   rendering.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var uri = GetUri(serviceProvider);

            string fileExt      = Path.GetExtension(Source);
            bool   isCompressed = !String.IsNullOrEmpty(fileExt) &&
                                  String.Equals(fileExt, ".svgz",
                                                StringComparison.OrdinalIgnoreCase);

            if (isCompressed)
            {
                using (Stream stream = Application.GetResourceStream(uri).Stream)
                    return(SvgReader.Load(new GZipStream(stream, CompressionMode.Decompress), new SvgReaderOptions {
                        IgnoreEffects = m_IgnoreEffects
                    }));
            }

            using (Stream stream = Application.GetResourceStream(uri).Stream)
                return(SvgReader.Load(stream, new SvgReaderOptions {
                    IgnoreEffects = m_IgnoreEffects
                }));
        }