Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
P

Polykar

@Polykar
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • WPF faster DrawingVisuals initialization.
    P Polykar

    Thanks a lot. Freezing the Pen did the Trick.

    WPF csharp database wpf graphics performance

  • WPF faster DrawingVisuals initialization.
    P Polykar

    Hello, We are planning to migrate to WPF. For a few use cases, drawingspeed is an issue. Drawing 10'000 mostly static lines on a zoomable/panable canvas is about as much as I need. Using DrawingVisuals, the performance is not acceptable, because the initialization takes around 10 seconds (which is ridiculous). After the initalization, the paning/zooming works fine. Please have a look at my sample code and tell me which part is terribly wrong...

            Pen pen = new Pen(Brushes.Red, 5);
            Random random = new Random();
    
            DrawingVisual visual = new DrawingVisual();
            using (DrawingContext dc = visual.RenderOpen())
            {
                for (int i = 0; i < 10000; i++)
                {
                    Point p1 = new Point(random.Next(0, 5000), random.Next(0, 5000));
                    Point p2 = new Point(random.Next(0, 100), random.Next(0, 100));
                    dc.DrawLine(pen, p1, new Point(p1.X - p2.X, p1.Y - p2.Y));
                }
                dc.Close();
            }            
            MyCanvas.AddVisual(visual);
    

    where MyCanvas is an overload of Canvas

    using System.Collections.Generic;
    using System.Windows.Controls;
    using System.Windows.Media;

    namespace WpfApplication1
    {
    public class DrawingCanvas : Canvas
    {
    private List _visuals = new List();

        protected override int VisualChildrenCount
        {
            get
            {
                return \_visuals.Count;
            }
        }
    
        protected override Visual GetVisualChild(int index)
        {
            return \_visuals\[index\];
        }
    
        public void AddVisual(Visual visual)
        {
            \_visuals.Add(visual);
            base.AddVisualChild(visual);
            base.AddLogicalChild(visual);
        }
    }
    

    }

    thanks a lot. regards. mike.

    WPF csharp database wpf graphics performance
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups