Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="shapes"></param>
        /// <param name="properties"></param>
        /// <param name="record"></param>
        /// <param name="ic"></param>
        /// <returns></returns>
        public MemoryStream MakeMetafileStream(Bitmap bitmap, IEnumerable <IBaseShape> shapes, ImmutableArray <IProperty> properties, IRecord record, IImageCache ic)
        {
            var g  = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new WinFormsRenderer(_serviceProvider, 72.0 / 96.0);
                    r.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
                    r.State.ImageCache           = ic;

                    g.SmoothingMode      = SmoothingMode.HighQuality;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    if (shapes != null)
                    {
                        foreach (var shape in shapes)
                        {
                            shape.Draw(g, r, 0, 0, properties, record);
                        }
                    }

                    r.ClearCache(isZooming: false);
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (mf != null)
                {
                    mf.Dispose();
                }
            }
            return(ms);
        }
Ejemplo n.º 2
0
    public MemoryStream?MakeMetafileStream(object bitmap, FrameContainerViewModel container, IImageCache ic)
    {
        var g  = default(Graphics);
        var mf = default(Metafile);
        var ms = new MemoryStream();

        if (bitmap is not Bitmap image)
        {
            return(null);
        }

        try
        {
            using (g = Graphics.FromImage(image))
            {
                var hdc = g.GetHdc();
                mf = new Metafile(ms, hdc);
                g.ReleaseHdc(hdc);
            }

            using (g = Graphics.FromImage(mf))
            {
                var p = new ExportPresenter();
                var r = new WinFormsRenderer(_serviceProvider, 72.0 / 96.0);
                r.State.DrawShapeState = ShapeStateFlags.Printable;
                r.State.ImageCache     = ic;

                g.SmoothingMode      = SmoothingMode.HighQuality;
                g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                g.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                g.PageUnit = GraphicsUnit.Display;

                if (container is PageContainerViewModel page)
                {
                    p.Render(g, r, null, page.Template, 0, 0);
                }
                p.Render(g, r, null, container, 0, 0);

                r.ClearCache();
            }
        }
        finally
        {
            g?.Dispose();

            mf?.Dispose();
        }
        return(ms);
    }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="container"></param>
        /// <param name="ic"></param>
        /// <returns></returns>
        public MemoryStream MakeMetafileStream(Bitmap bitmap, IPageContainer container, IImageCache ic)
        {
            var g  = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new WinFormsRenderer(_serviceProvider, 72.0 / 96.0);
                    r.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
                    r.State.ImageCache           = ic;

                    g.SmoothingMode      = SmoothingMode.HighQuality;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    r.Draw(g, container.Template, 0.0, 0.0);
                    r.Draw(g, container, 0.0, 0.0);

                    r.ClearCache(isZooming: false);
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (mf != null)
                {
                    mf.Dispose();
                }
            }
            return(ms);
        }
Ejemplo n.º 4
0
        public MemoryStream MakeMetafileStream(Bitmap bitmap, IEnumerable <BaseShapeViewModel> shapes, IImageCache ic)
        {
            var g  = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new WinFormsRenderer(_serviceProvider, 72.0 / 96.0);
                    r.State.DrawShapeState = ShapeStateFlags.Printable;
                    r.State.ImageCache     = ic;

                    g.SmoothingMode      = SmoothingMode.HighQuality;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    foreach (var shape in shapes)
                    {
                        shape.DrawShape(g, r, null);
                    }

                    r.ClearCache();
                }
            }
            finally
            {
                g?.Dispose();

                mf?.Dispose();
            }
            return(ms);
        }