简体   繁体   English

将字符串列表转换为CGPoint数组

[英]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. 我正在做的基础是使用CGPoint数组存储绘制的签名中的多个CGPoint,然后将该数组中的每个值存储到本地SQLite上的字符串数组中。

I am them retrieving this SQLite data and passing it back into the same List after clearing it. 我是他们检索此SQLite数据并将其清除后传递回相同的List中。 I need to convert this List into a CoreGraphics.CGPoint Array so I can re-display the array into the signature area. 我需要将此列表转换为CoreGraphics.CGPoint数组,以便可以将数组重新显示在签名区域中。 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 这就是我将CGPoint数组转换为列表的方式

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 编辑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? 您使用foreach进行了初始转换,还使用foreach尝试了逆向转换吗?

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). 为了解析字符串值,我会尝试类似的事情(注意RegEx在这里可能有用,但这不是我的强项)。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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