canvas - c# InkStrokeBuilder loss of data -


i have drawing project user can create drawings, server , use elsewhere (on other platforms)

to achieve this, can drawings in collection of points scheme, using following object.

public class drawing {     public drawing()     {         points = new list<list<int>>();     }     public list<list<int>> points { get; set; }     public string colour { get; set; } } 

i use c# inkmanager me draw sketches. save, extract strokes , save them list of points, follows.

private list<drawing> getdrawingsfrominkmanager()     {         list<drawing> returnlist = new list<drawing>();         var strokes = m_inkmanager.getstrokes();          int scount = 1;          foreach (var s in strokes)         {             var renderingstrokes = s.getrenderingsegments();              drawing drawing = new drawing() { colour = m_currentdrawingcolor.tostring() };              foreach (var rs in renderingstrokes)             {                 drawing.points.add(new list<int>() { (int)rs.position.x, (int)rs.position.y });             }              debug.writeline("drawing: " + scount++ + " points added: " + drawing.points.count + " rendersegmentscount: " + renderingstrokes.count);              returnlist.add(drawing);          }         return returnlist;     } 

result output is:

drawing: 1 points added: 33 rendersegmentscount: 33

drawing: 2 points added: 22 rendersegmentscount: 22

drawing: 3 points added: 21 rendersegmentscount: 21

during process, bezier curve data lost, should not concern, set of straight segments acceptable (the points vary 1-2 pixels).

when restoring points, use c# strokebuilder class , pass list of points. however, resulting stroke has half strokes.

private void restoresegmentfromlist(list<point> pointlist)     {         var color = m_currentmode == "ink" ? m_currentdrawingcolor : m_currenthighlightcolor;         var size = m_currentmode == "ink" ? m_currentdrawingsize : m_currenthighlightsize;          inkstrokebuilder isbuiler = new inkstrokebuilder();         var points = pointlist.select(x => new point(x.x* sketchscale, x.y*sketchscale)).tolist();          var inkstroke = isbuiler.createstroke(points);         m_inkmanager.addstroke(inkstroke);          debug.writeline("restoring; points added: " + points.count + " rendersegmentscount: " + inkstroke.getrenderingsegments().count);      } 

restoring; points added: 33 rendersegmentscount: 16

restoring; points added: 22 rendersegmentscount: 14

restoring; points added: 21 rendersegmentscount: 12

my question, intended behaviour of strokebuilder class? way understand strokes consist of 1 position , 2 bezier control points. position endpoint of particular segment of stroke, end-point of previous segment being start of current one. far i'm aware methods above use same manner extract create. surely if x number of rendering segments inkmanager should able restore said x number, using set of points. using createstroke() method wrong?

to save, extract strokes , save them list of points.

why this, can save inkstroke objects specified stream using inkstrokecontainer.saveasync | saveasync method. there official simple inking sample, in scenario 3, drawings can saved files , loaded files. if don't want save locally, can create inmemoryrandomaccessstream, , upload stream. example:

using (var stream = new inmemoryrandomaccessstream()) {     await inkcanvas.inkpresenter.strokecontainer.saveasync(stream);      //todo: upload stream. } 

and when want load inkstroke on other platforms, can download stream and:

await inkcanvas.inkpresenter.strokecontainer.loadasync(stream);   

this might not perfect answer data-lost issue, think how strokes correctly saved , loaded , simpler.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -