iOS AssetLibrary 存储指针
我有一个关于在 iOS 上使用 AssetLibrary 的问题。是否可以在应用程序中存储指向图像而不是实际图像的指针?假设我想创建一个播放列表,但我不想存储实际图像。
我问的原因是,我发现当我使用图像选择器时,我可以将图像保存到设备文档目录中,但是一旦我达到 25 左右,它就会开始减慢设备速度(iPad 1)。如果图像非常大,我会按比例缩小图像,我多次运行泄漏仪器,并且没有泄漏。我只是不知道下一步该去哪里,所以我想研究替代方案。因为我看不到任何地方可以释放内存。
这就是我现在所处的位置,我很好奇 AssetLibrary 是否可以作为一个选项,因为我不会存储物理图像。我知道它有一些缺点(需要用户位置,循环浏览图像时可能会有点慢)
对此的任何想法将不胜感激。
I have a question on using the AssetLibrary with iOS. It it possible to store a pointer to an image in your app rather than the actual image? Let's say I want to create a playlist, but I don't want to store the actual image.
The reason I am asking, is that I find when I use the image picker, I can save an image to the devices documents directory, but once I get to 25 or so, it starts to slow down the device (iPad 1). I scale down the images if they are very large, I ran through the leaks instrument many times, and there are no leaks. I am just at a loss as to where to turn next, so I wanted to investigate alternatives. As I see nowhere where I can free up memory.
That's where I am at now, I'm curious if the AssetLibrary might be a option since I won't be storing physical images. I know it has some dis-advantages (requires users location, can be a bit slow when looping through images)
Any thoughts on this would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 25 个图像存储到文档目录不会降低设备速度,除非您尝试同时将所有 25 个极大图像加载到内存中。
您无法永久存储指向资源库资源的指针,但可以存储从 ALAssetRepresentation 的
url
属性检索到的 URL,然后使用 ALAssetsLibrary 的assetForURL:resultBlock:failureBlock:
稍后取回相应的 ALAsset。请注意,即使您的应用程序位于后台,用户也可以从程序外部删除资产,因此,如果您正在使用 ALAsset,则必须侦听 ALAssetsLibraryChangedNotification 以了解何时重新加载资产。Storing 25 images to the documents directory shouldn't slow down the device, unless you're trying to load all 25 extremely large images into memory at the same time.
You can't permanently store a pointer to the assets library asset, but you can store the URL you retrieve from the ALAssetRepresentation's
url
property and then use ALAssetsLibrary'sassetForURL:resultBlock:failureBlock:
to get back the corresponding ALAsset later. Do note that it is possible for the user to delete the asset from outside your program, even when your app is in the background, so if you are hanging on to an ALAsset you must listen for ALAssetsLibraryChangedNotification to know when to reload the assets.