c# - Is there a way to add data to DrawingVisual -
i have custom drawn control (overrides frameworkelement
) several drawingvisual
objects. i'm keeping list of visuals , overriding getvisualchild
, visualchildrencount
. performance important, of them use bitmapcache
.
one of visuals going updated new data every 50 ms. draws path machine takes in real world, every 50 ms. there's new line draw, keeping old lines still there.
what best way draw performance, without redrawing existing machine path, adding line? seems once draw in visual using renderopen
can't modify it. tried visual.drawing.append()
seems doesn't draw anything.
is there way add new data drawingvisual
? if not, use instead?
perhaps create rendertargetbitmap draw instead, when onrender call made context.drawimage
using system; using system.componentmodel; using system.windows; using system.windows.media; using system.windows.media.imaging; namespace wpfapplication13 { public class paneltest : frameworkelement { public rendertargetbitmap _rendertargetbitmap = null; public system.windows.threading.dispatchertimer _timer = null; public int _iyloc = 0; private pen _pen = null; protected override void onrender(drawingcontext drawingcontext) { if (!designerproperties.getisindesignmode(this)) { drawingcontext.drawimage(_rendertargetbitmap, new rect(0, 0, 250, 250)); } base.onrender(drawingcontext); } public paneltest() :base() { _rendertargetbitmap = new rendertargetbitmap(250, 250, 96, 96, system.windows.media.pixelformats.pbgra32); _pen = new pen(brushes.red, 1); _timer = new system.windows.threading.dispatchertimer(); _timer.interval = new timespan(0, 0, 0, 0, 50); _timer.tick += _timer_tick; if (!designerproperties.getisindesignmode(this)) { _timer.start(); } } private void _timer_tick(object sender, eventargs e) { drawingvisual vis = new drawingvisual(); drawingcontext con = vis.renderopen(); con.drawline(_pen, new point(0, _iyloc), new point(250, _iyloc)); _iyloc++; con.close(); _rendertargetbitmap.render(vis); } } }
Comments
Post a Comment