Sample for DrawingVisual (trying to avoid Bitmap images)

Stimulsoft Reports.WPF discussion
Post Reply
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by euregon »

Hi,

can you please point me to a sample using DrawingVisual instead of Bitmap images for an Image?

Thanks a lot.

I tried the following code, but the image isn't recocniced in the designer:

Code: Select all

   public class MyDrawing
    {
        private DrawingVisual _drawing = null;

        public DrawingVisual Drawing 
        {
            get { return _drawing; }            
        }

        public int ID
        {
            get { return 17; }
        }

        public MyDrawing()
        {
            _drawing = new DrawingVisual();
            using (DrawingContext dc = Drawing.RenderOpen())
            {
                // The body
                dc.DrawGeometry(Brushes.Blue, null, Geometry.Parse(
                                @"M 240,250
                            C 200,375 200,250 175,200
                            C 100,400 100,250 100,200
                            C 0,350 0,250 30,130
                            C 75,0 100,0 150,0
                            C 200,0 250,0 250,150 Z"));
                // Left eye
                dc.DrawEllipse(Brushes.Black, new Pen(Brushes.White, 10),
                new Point(95, 95), 15, 15);
                // Right eye
                dc.DrawEllipse(Brushes.Black, new Pen(Brushes.White, 10),
                new Point(170, 105), 15, 15);
                // The mouth
                Pen p = new Pen(Brushes.Black, 10);
                p.StartLineCap = PenLineCap.Round;
                p.EndLineCap = PenLineCap.Round;
                dc.DrawLine(p, new Point(75, 160), new Point(175, 150));
            }
        }
    }
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by euregon »

Anton Lozovskiy
Posts: 135
Joined: Tue Aug 11, 2009 9:38 am

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by Anton Lozovskiy »

Hello,

We create an example for you, please see.

Thank you.
Attachments
957.WpfApplication1.zip
(9.93 KiB) Downloaded 457 times
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by euregon »

Hi AntonLoz,

thank you for your code.

I noticed in your example, you are using RenderTargetBitmap for offline rendering. This will create a Bitmap resource?

By using Image1.ObjectToDraw = myDrawing; in the BeforePrintEvent in the report, i got the DrawingVisual
as pure vector graphic in the designer an preview.

I was hoping that the PDF export will keep the DrawingVisual as vector graphics.

However i could only export it with a JPEG image inside.

Is there any other trick we can keep the image as vector? Can Stimulsoft use EMF/WMF images in the
report as vector or convert a DrawingVisual to a EMF/WMF inside the report system?
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by Jan »

Hello,
I noticed in your example, you are using RenderTargetBitmap for offline rendering. This will create a Bitmap resource?

By using Image1.ObjectToDraw = myDrawing; in the BeforePrintEvent in the report, i got the DrawingVisual
as pure vector graphic in the designer an preview.

I was hoping that the PDF export will keep the DrawingVisual as vector graphics.

However i could only export it with a JPEG image inside.
Its correct. At this moment export to pdf ca use only png or jpeg images.
Is there any other trick we can keep the image as vector? Can Stimulsoft use EMF/WMF images in the
report as vector or convert a DrawingVisual to a EMF/WMF inside the report system?
Sorry this is not possible now. This is very complex task and we don't plan release this feature in near future. At this moment exist only one way to export vector images to pdf file - though rich text object. Pdf export use special methodic to convert rich text object (including images in it) to vector primitives of pdf.

Thank you.
euregon
Posts: 21
Joined: Thu Apr 21, 2011 8:13 am
Location: Germany, Augsburg

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by euregon »

Jan wrote:
Sorry this is not possible now. This is very complex task and we don't plan release this feature in near future. At this moment exist only one way to export vector images to pdf file - though rich text object. Pdf export use special methodic to convert rich text object (including images in it) to vector primitives of pdf.

Thank you.
Hello Jan,

indeed it's very complex to render WPF vector graphic to PDF as vectors :)

As you can see our grapic objects are quite simple. So the rich text might be a nice simple way.

Can you point me to an example with the rich text object?

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Sample for DrawingVisual (trying to avoid Bitmap images)

Post by Alex K. »

Hello,

Unfortunately, it is not possible.
This is a very narrowly specific feature which is very rarely demanded. Therefore, at this moment, we do not have plans to implement it.

Thank you.
Post Reply