苹果在 GLPaint 示例中使用什么样的数据? [英] What kind of data does apple use on GLPaint example?

查看:48
本文介绍了苹果在 GLPaint 示例中使用什么样的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,我制作了一个基于苹果 GLPaint 的应用程序.效果很好.

Few months ago i made an app based on apple GLPaint. It works great.

我记录了在屏幕上绘制简单图形的点集.并将它们保存为点数组(转换为 NSValue).

I have recorded sets of points that draw simple drawings on the screen. and saved them as array of points (converted to NSValue).

我现在正在尝试改进我的应用程序,我再次查看了苹果示例.他们的数据文件中的数据看起来像这样(我已经稍微改变了它):

i am trying to improve my app now and i looked again at apple example. the data in their data file looks like that (i have changed it a little bit):

<data>
AAC8QgAAsEMAAMJCAICoQwAAwkIBBAKRDAADCQgCAnUMAAMJCAACYQwAAwEIAgJRDAADA
QgCAkkMAAMBCAACRQwAAwEIAgJBDAADAQgCAkEM=
</data>
<data>
AACoQgAAnEMAALpCAACdQwAAxEIAAJ1DAAGGGgAAnUMAANpCAICdQwAA4kIAgJ5DAADs
QgCAn0MAAOxCAICfQw==
</data>

所以每组都是一张图,这比我的 CGPoints 的 plist 更紧凑.

So every group is one drawing and This is way compact then my plists of CGPoints.

我已成功将 CGPoints 数组转换为数据并读回文件.

I have succeeded to convert the array of CGPoints to data and read the file back.

但是当我尝试打开每个形状数据文件时,我得到了这个(在 textMate、textEdit、xCode...上):

BUT When i try to open each shape data file i get this (on textMate, textEdit, xCode...):

我想明白:

  1. 苹果使用什么来获取 CGPoints 列表的这种压缩格式?
  2. 如何以更易读的方式打开我的数据文件?

推荐答案

Apple 的 Recording.data 文件中的数据 示例应用程序 是包含一堆 NSData 对象,每个对象都包含表示 CGPoint 结构数组的字节.请注意,这取决于 CGFloat 的二进制表示和 CGPoint 结构的特定布局,这可能因编译器或同一编译器的版本而异.

The data in Apple's Recording.data file in that sample application is the XML Plist representation of an NSArray containing a bunch of NSData objects, each of which contains the bytes representing an array of CGPoint structs. Do note that this depends on the binary representation of a CGFloat and the specific layout of the CGPoint struct, which could differ between compilers or versions of the same compiler.

您的屏幕截图似乎是 NSKeyedArchiver 的输出,它更安全但开销更大.

Your screenshot appears to be the output of NSKeyedArchiver, which is safer but has much more overhead.

如果您想要一个紧凑但仍然可移植的表示,您可以手动将单个 CGFloats 序列化为可移植格式的字节数组 (this previous question 可能会帮助你)然后将字节数组包装在 NSData 中,将 NSDatas 放入 NSArray,并使用 writeToFile:atomically: 输出混乱到像 Apple 一样的 plist.

If you wanted a compact but still portable representation, you could manually serialize the individual CGFloats into a byte array in a portable format (this previous question may help you there) and then wrap the byte arrays in NSData, put the NSDatas into an NSArray, and use writeToFile:atomically: to output the mess to a plist like Apple does.

这篇关于苹果在 GLPaint 示例中使用什么样的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆