简体   繁体   中英

Convert String List to CGPoint Array

I have an issue which I am not sure is even possible to fix but really need some help if it is possible. The basis of what I am doing is using a CGPoint array for storing multiple CGPoints from a drawn signature and then storing each value from this array into a string array on a local SQLite.

I am them retrieving this SQLite data and passing it back into the same List after clearing it. I need to convert this List into a CoreGraphics.CGPoint Array so I can re-display the array into the signature area. I have tried various ways of doing this but it just seems impossible.

Hopefully someone can help me with this issue.

EDIT

This is how I convert the CGPoint Array into a List

var tempSignatureArray = signatureView.Points;

        foreach (var item in tempSignatureArray)
        {
            var tempItem = item.ToString();
            FormResults.signaturePoints.Add(tempItem);
        }

This is what I have tried with various other method which I have now gotten rid off:

var test = FormResults.signaturePoints.ToArray();

        CoreGraphics.CGPoint[] pointArray = test;

Edit 2

Below is what is actually stored in the String List

{X=394.4296875, Y=71.359375}
{X=399.125, Y=71.875}
{X=405.2578125, Y=72.453125}
{X=412.5, Y=73}
{X=421.6875, Y=73.546875}
{X=432.6875, Y=74.125}

you did the initial conversion with a foreach, did you try the inverse using a foreach also?

List<CGPoint> pointList = new List<CGPoint>();

foreach (var p in FormResults.signaturePoints)
{
  // p is the string representation

  // you will need to do some parsing to convert the string p into x,y coords
  pointList.Add(new CGPoint(x,y));
}

pointArray = pointList.ToArray();

to parse the string value, I'd try something like this (note RegEx might be useful here, but that's not my strength).

var s = "{X=394.4296875, Y=71.359375}";
var ss = s.Split(',');

var x1 = ss[0] .Substring(3, ss[0].Length-3);
double x = Double.Parse(x1);

var y1 = ss[1].Substring(3, ss[1].Length-3);
y1 = y1.Substring(0,y1.Length-1);
double y = Double.Parse(y1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM