Ejemplo n.º 1
0
        /// <summary>
        /// Renders the <see cref="SvgDocument"/> into a given Bitmap <see cref="Bitmap"/>.
        /// </summary>
        public virtual void Draw(Bitmap bitmap)
        {
            //Trace.TraceInformation("Begin Render");

            using (var renderer = SvgRenderer.FromImage(bitmap))
            {
                var boundable = new GenericBoundable(0, 0, bitmap.Width, bitmap.Height);
                this.Draw(renderer, boundable);
            }

            //Trace.TraceInformation("End Render");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the <see cref="SvgDocument"/> into a given Bitmap <see cref="Bitmap"/>.
        /// </summary>
        public virtual void Draw(Bitmap bitmap)
        {
            //Trace.TraceInformation("Begin Render");

            using (var renderer = SvgRenderer.FromImage(bitmap))
            {
                // EO, 2014-12-05: Requested to ensure proper zooming out (reduce size). Otherwise it clip the image.
                this.Overflow = SvgOverflow.Auto;

                var boundable = new GenericBoundable(0, 0, bitmap.Width, bitmap.Height);
                this.Draw(renderer, boundable);
            }

            //Trace.TraceInformation("End Render");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders the <see cref="SvgDocument"/> in given size and returns the image as a <see cref="Bitmap"/>.
        /// If one of rasterWidth and rasterHeight is zero, the image is scaled preserving aspect ratio,
        /// otherwise the aspect ratio is ignored.
        /// </summary>
        /// <returns>A <see cref="Bitmap"/> containing the rendered document.</returns>
        public virtual Bitmap Draw(int rasterWidth, int rasterHeight)
        {
            var imageSize  = GetDimensions();
            var bitmapSize = imageSize;

            this.RasterizeDimensions(ref bitmapSize, rasterWidth, rasterHeight);

            if (bitmapSize.Width == 0 || bitmapSize.Height == 0)
            {
                return(null);
            }

            Bitmap bitmap = null;

            try
            {
                try
                {
                    bitmap = new Bitmap((int)Math.Round(bitmapSize.Width), (int)Math.Round(bitmapSize.Height));
                }
                catch (ArgumentException e)
                {
                    // When processing too many files at one the system can run out of memory
                    throw new SvgMemoryException("Cannot process SVG file, cannot allocate the required memory", e);
                }

                using (var renderer = SvgRenderer.FromImage(bitmap))
                {
                    renderer.ScaleTransform(bitmapSize.Width / imageSize.Width, bitmapSize.Height / imageSize.Height);
                    var boundable = new GenericBoundable(0, 0, imageSize.Width, imageSize.Height);
                    this.Draw(renderer, boundable);
                }
            }
            catch
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
                throw;
            }

            return(bitmap);
        }