将byte []转换为Point []并返回

时间:2017-11-10 01:27:50

标签: c# xamarin

是否可以将byte []转换为Point?我有一个画布和绘图获得点[];我需要将它作为byte []存储在数据库中,然后检索它并再次加载为Point []。

1 个答案:

答案 0 :(得分:2)

您可以将点序列化为二进制流以获取字节数组:

Point[] points;
using (var ms = new MemoryStream(data)) {
    using (var r = new BinaryReader(ms)) {
        int len = r.ReadInt32();
        points = new Point[len];
        for (int i = 0 ; i != len ; i++) {
            points[i] = new Point(r.ReadInt32(), r.ReadInt32());
        }
    }
}

要将字节反序列化为数组,请反转该过程:

main.cpp: In function 'int main(int, char**)':
main.cpp:49:12: error: the default argument for parameter 0 of 
'Camera::Camera(QWidget*)' has not yet been parsed
Makefile:1292: recipe for target 'main.o' failed
make: *** [main.o] Error 1