Iphone 视网膜显示屏与 Core Data 用户生成的图像
我已经在这个论坛上关注这个主题有一段时间了,但仍然不清楚如何成功地将图像存储在核心数据中以用于视网膜显示。
我知道通过 Core Data 存储图像可能并不适合每个人,但在出于某种原因这样做的情况下,了解这些图像的读取和显示方式非常重要。
由于图像没有文件扩展名,因此视网膜版本(如果存在)显然不能有 2x 扩展名。
因此,我希望有人可以建议我如何最好地存储通过应用程序创建的位图图像,以便它们在视网膜和非视网膜设备上都有最佳显示效果。
例如,如果在我的非视网膜 3GS iPhone 上,我有一个显示 55x60 图像的 UIImageView,那么我当前存储的图像“缩略图”为 55x60。
在视网膜显示屏上,显然我希望显示 110x120 的图像。
但是,由于我无法在核心数据中创建带有扩展名的图像,我该如何做呢?
如果我决定只创建一个用于两个设备的图像,我是否只使用 110x120 的图像?它是如何工作的 - 它会为视网膜显示设备使用完整图像并为非视网膜设备缩小图像吗?或者(我希望不是)它会为非视网膜设备缩小图像并为视网膜再次放大图像吗?
提前致谢!
I have been looking at this forum on this topic for a while now and still don't have a clear picture of how to store images in Core Data successfully for Retina Display.
I understand that storing images through Core Data may not be the best for everyone, but in cases where it is being done for one reason or another, it is important to understand how these images are read and displayed.
Since the images don't have a file extension, the retina versions (if they exist) obviously cannot have a 2x extension.
So I am hoping someone can advise me as to how to what resolutions would be best to store bitmap images created through the app so that they have the best display in both retina and non-retina devices.
For example, if on my non-retina 3GS iPhone I have a UIImageView that displays a 55x60 image, I currently store an image "thumbnail" that is 55x60.
On the retina display, obviously I would like to have an image that is 110x120 to display.
But, since I can't create an image with an extension in core-data, how would I go about doing this?
If I decide just to create one image that will be used for both devices, do I just go with a 110x120 image? How does that work - will it use the full image for the retina display device and scale down the image for the non-retina device? Or (and I hope NOT) will it scale the image down for the non-retina device and scale it back up again for retina?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先也是最重要的一点:不要将图像存储在 Core Data 中。在文件系统(即文档目录)上存储图像并使用 Core Data 来存储参考会更容易(并且性能更高!)。
也就是说,如果您坚持使用 Core Data 来存储该数据,您可以存储 Retina 版本,然后检测您何时使用非 Retina 设备,并对非 Retina 版本进行内存缩放。
First and foremost: don't store images in Core Data. It is just easier (and more performant!) to store an image on the filesystem (ie. documents directory) and use Core Data to store the reference.
That said, if you are insistent in using Core Data to store that data, you could store the Retina version and then detect when you are on a non-retina device and do an in-memory scale to the non-Retina version.
您想要将 UIImage 存储在 CoreData 中,以便您的图像不会被操作系统自动“清理”,这是您想要的部分原因吗?
如果没有,您应该像 Wayne 提到的那样,在 Documents 目录中创建对文件路径的引用。
如果“清理”是您试图避免的问题,那么只需将 UIImage 的 NSData 存储为 NSManagedObject 的属性之一,然后在使用时适当缩放它。或者,您始终可以先缩放图像,然后再将其放入 CoreData。
Is part of the reason you want to store UIImages in CoreData so that your Images do not get "Cleaned" automatically by the OS?
If not, you should do as Wayne mentioned and just create references to a file path in the Documents directory.
If "cleaning" is the problem you are trying to avoid, then just store the UIImage's NSData as one of the NSManagedObject's properties, and then upon use scale it appropriately. Alternatively, you could always scale the images before putting them into CoreData.