Path vs GeometryDrawing
Asked Answered
P

1

8

Just wondering what's lighter, I'm going to have a control that draws 280 * 4 my SegmentControl, which is a quarter of a circle, and I'm just wondering what's the way that takes least memory to draw said segment.

GeometryDrawing:

<Image>
    <Image.Source>
        <DrawingImage>
            <DrawingImage.Drawing>
                <GeometryDrawing Brush="LightBlue"
                                 Geometry="M24.612317,0.14044853 C24.612317,0.14044853 33.499971,-0.60608719 41,7.0179795 48.37642,14.516393 47.877537,23.404541 47.877537,23.404541 L24.60978,23.401991 z" />
            </DrawingImage.Drawing>
        </DrawingImage>
    </Image.Source>
</Image>

Or Path:

<Path Fill="LightBlue"
              Stretch="Fill"
              Stroke="#FF0DA17D"
              Data="M24.612317,0.14044853 C24.612317,0.14044853 33.499971,-0.60608719 41,7.0179795 48.37642,14.516393 47.877537,23.404541 47.877537,23.404541 L24.60978,23.401991 z" />

Or if you know of an even better way, it'll be much appreciated.

Thanks!

Peachy answered 22/4, 2010 at 20:20 Comment(1)
I was wondering the precision of a number like 0.14044853 (1E-8 unit). In WPF there are 96 units per inch, 100 units (1E2) are 26 mm, so 1E-1 unit is 26 μm (smaller than one pixel), 1E-3 is 260 nm ((it's so small nobody can see it, even with the most powerful optical microscope), 1E-5 is 2.6 nm (the length a fingernail grows in 3 seconds, judge by yourself) and 1E-8 is 2.6 pm, about the size of an electron (well below the resolution of an electron microscope) That's as funny as if we stated a year (like 2019) with 10 figures (0000002019), just to be sure we won't exceed the capacity :-)Impale
D
0

If you want a better performance you can look into "drawing visual". It is more complicated but, also more performant.

https://learn.microsoft.com/en-us/dotnet/desktop/wpf/graphics-multimedia/using-drawingvisual-objects?view=netframeworkdesktop-4.8

However you will need to understand how to draw each desired shape.

sample:

 // Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext in order to create new drawing content.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Create a rectangle and draw it in the DrawingContext.
    Rect rect = new Rect(new System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
    drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);

    // Persist the drawing content.
    drawingContext.Close();

    return drawingVisual;
}
Deadwood answered 17/7, 2023 at 19:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.