将图像存储在文件系统与核心数据中 [英] Storing Images in file system vs. Core Data

查看:130
本文介绍了将图像存储在文件系统与核心数据中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个iOS应用程序,我允许用户将他们的照片库中的图像添加到应用程序中。我将这些图像存储在设备文件系统上,并在需要时访问它们(当他们在UIScrollView中时,我可以经常访问它们)。



对这种方法有一些意见。我应该保留文件系统方法,或者将这些I图像存储在CoreData中是有益的。



对此有任何建议将非常感谢。 >

感谢。

解决方案

我不认为Core Data存储此类型的数据。这样做的道义等同于将图像数据存储到SQL /关系数据库中,这是不理想的。



我有一个类似的情况,我有一堆的图像存储在硬目标位置(我的图像列表从不更改,因此我只是将它们全部包含在应用程序包中)与包含大量关于图像的元数据的Core Data存储。所有我保留在图像本身的核心数据是文件名,然后mash在一起的运行时,当它是最终看到图像的完整文件路径。我没有任何滞后时间或延迟的问题。



即使我没有在UIScrollView中显示图像,我仍然认为你会有一点问题从Core Data存储中提取图像信息数组,并在生成单元格的同时生成完整的文件路径,因为它们只是字符串,用于生成UIImage的代码非常紧凑。或者生成相同的信息数组,然后在生成任何单元格之前编译一个图像路径数组,就像当UIScrollView即将出现时一样。


I am currently working on an iOS application that I allow the user to add images from their photo library into the application. I store these images on the devices file system, and access them when I need them (when they are in a UIScrollView, I could access them quite often)

I just wanted to get some opinions on this approach. Should I stay with the file system method, or would it be beneficial to store these I images in CoreData instead.

Any suggestions on this would be greatly appreciated.

Thanks.

解决方案

I don't think Core Data was really designed for storing this type of data. Doing so would be the moral equivalent of storing the image data into a SQL/relational database which isn't ideal either.

I have a similar situation where I have a bunch of images stored in hard targetted location (my image list never changes, so I just include them all in the application bundle) with a Core Data store that contains a lot of metadata about the images. All I keep in the Core Data of the image itself is the file name and then mash together the full file path during runtime when it is finally time to see the image. I don't have any problems with lag time or delays.

Even though I'm not showing the images in a UIScrollView, I still think you'd have little problem fetching the array of image information from the Core Data store and generating the full file path on the fly as cells are generated since those are just strings and the code for generating the UIImage is very compact. That or generate the same array of information, and then compiling an array of image paths before any cells are generating, like when the UIScrollView is just about to appear.

这篇关于将图像存储在文件系统与核心数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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