简体   繁体   English

如何将从Web检索到的图像存储到应用程序捆绑包中?

[英]How could I store Image retrieved from web, into application bundle?

I am developing iPhone application and In that application I've one TableViewController , and that TableViewController made up of Custom table cell. 我正在开发iPhone应用程序,在该应用程序中,我有一个TableViewController ,而该TableViewController由“定制”表单元格组成。
into those cell I am loading image from URL, but the scrolling is not that smooth, (because each cell load images every time when scrolling happen). 到这些单元格中,我是从URL加载图像,但是scrolling不是那么顺畅,(因为每个单元格每次滚动时都会加载图像)。

So I decided to store those images into application document folder, but I don't know how to use document folder in iPhone when application is in running state. 因此,我决定将这些图像存储到应用程序文档文件夹中,但是当应用程序处于运行状态时,我不知道如何在iPhone中使用文档文件夹。

Any suggestion? 有什么建议吗?

And on other forums I found that SQLITE has blob datatype to store binary data, 在其他论坛上,我发现SQLITE具有blob数据类型来存储二进制数据,

Which method is efficient, document folder or sqlite to store image? 哪种方法最有效,使用文档文件夹或sqlite存储图像?

Storing the images on the device may improve things somewhat, but it will not make scrolling really smooth. 将图像存储在设备上可能会有所改善,但不会使滚动真正平滑。 The reason scrolling tends to become choppy is that a synchronous function in your cell code means that you are blocking the run loop, which prevents animation. 滚动变得不稳定的原因是单元格代码中的同步功能意味着您阻塞了运行循环,从而阻止了动画。 If you want to speed up scrolling you need to get rid of the blocking event, by making it asynchronous (though this still may result it chunky scrolling if you're asynch callbacks take a lot of CPU time), or moving the blocking code off the main thread. 如果您想加快滚动速度,则需要通过使它成为异步来摆脱阻塞事件(尽管如果您使用的是回调回调,这会导致它的滚动时间很长,但它会占用大量CPU时间),或者将阻塞代码移开主线程。

If you move your loads off the main thread then either individual files or an sqlite3 database will work fine. 如果将负载从主线程上移开,则单个文件或sqlite3数据库都可以正常工作。 The other big issue you will find is that cells are not updated while scrolling. 您会发现的另一个大问题是,滚动时不会更新单元格。 That means if you perform an asynch image load in responds to the cell loading the image will not appear in the cell until the user is done scrolling, which is generally not the desired experience. 这意味着,如果响应于单元格加载而执行异步图像加载,则在用户完成滚动之前,图像不会出现在单元格中,这通常不是理想的体验。 In order to do avoid that you need to predictively load the images into ram before the user scrolls over them. 为了避免这种情况,您需要在用户滚动图像之前将其图像预测加载到ram中。

You could use NSFileManager 's createFileAtPath to save any NSData into a file. 您可以使用NSFileManagercreateFileAtPath将任何NSData保存到文件中。

To get the Documents directory, use this: 要获取Documents目录,请使用以下命令:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从iphone应用程序将值存储在Web服务器中 - How to store the values in web server from i phone application Apple商店和应用程序包 - Apple store and application bundle 如何从我的应用程序启动我的设置包? - How do I launch my settings bundle from my application? 如何检查是否可以使用NSError从捆绑读取图像? - how to check if i can read image from bundle using NSError? 无法加载从设备上运行的包中的笔尖引用的图像 - Could not load the image referenced from a nib in the bundle running on device 无法加载带有标识符的包中的nib引用的图像 - Could not load the image referenced from a nib in the bundle with identifier 无法加载标识符为“(null)”的包中的nib引用的图像 - Could not load the image referenced from a nib in the bundle with identifier “(null)” 无法加载从带有标识符的包中的笔尖引用的“”图像 - Could not load the "" image referenced from a nib in the bundle with identifier 如何从iPhone中的应用程序包播放视频 - How to play video from application bundle in iPhone 错误代码:无法加载标识符为“com.bundle.identifier”的包中从nib引用的“image.png”图像 - Error code: Could not load the “image.png” image referenced from a nib in the bundle with identifier “com.bundle.identifier”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM