简体   繁体   English

如何在没有缓存的Monotouch中从文件加载UIImage?

[英]How to load a UIImage from file without caching in Monotouch?

If I look at the discussion here: http://monotouch.2284126.n4.nabble.com/UIImageView-td4303177.html 如果我看一下这里的讨论: http//monotouch.2284126.n4.nabble.com/UIImageView-td4303177.html

Both, UIImage.FromFile() and UIImage.FromFileUncached() map to imageWithContentsOfFile: and are not supposed to cache, however my experience is different and I'm pretty sure that UIImage.FromFile() caches (from what I see in Instruments). 两者, UIImage.FromFile()UIImage.FromFileUncached()映射到imageWithContentsOfFile:并且不应该缓存,但是我的经验是不同的,我很确定UIImage.FromFile()缓存(从我在Instruments中看到的) 。

The documentation here (http://docs.xamarin.com/ios/tutorials/Working_with_Images) states that UIImage.FromBundle() does cache, but UIImage.FromFile() does not. 这里的文档(http://docs.xamarin.com/ios/tutorials/Working_with_Images)声明UIImage.FromBundle()确实缓存,但UIImage.FromFile()没有。 Is that still true? 这仍然是真的吗? Or is there maybe some magic that FromFile() caches if the image is inside the app bundle? 或者,如果图像在应用程序包中,可能会有一些神奇的FromFile()缓存?

Can somebody please make clear what is the correct way to: 有人可以说明正确的方法是什么:

  • Load a UIImage with caching? 使用缓存加载UIImage?
  • Load a UIImage without caching ? 在没有缓存的情况下加载UIImage?

UIImage.FromFile and UIImage.FromFileUncached are identical . UIImage.FromFileUIImage.FromFileUncached相同的 They both call the same imageWithContentsOfFile: selector. 它们都调用相同的imageWithContentsOfFile: selector。

Xamarin's documentation on FromFileUncached explain why this was done. Xamarin关于FromFileUncached的文档解释了为什么这样做了。

Alias to FromFile, merely with a more explicit name to draw attention to the cache-less nature of this call compared to FromBundle. FromFile的别名,只是用一个更明确的名称来引起人们对此调用的无缓存性质的注意,与FromBundle相比。

Historically the original API for this selector was named FromFileUncached , while the old FromFile method was mapped to imageNamed: - but it turned out this was a mistake since the later selector means from the bundle. 从历史上看,此选择器的原始API名为FromFileUncached ,而旧的FromFile方法已映射到imageNamed: - 但事实证明这是一个错误,因为后面的选择器意味着来自bundle。

A new FromBundle methods was added and, not to break the API, FromFile became identical to FromFileUncached . 添加了一个新的FromBundle方法,而不是破坏API, FromFile变得与FromFileUncached相同。

I'll add an [Obsolete] attribute to the FromFileUncached method since it will make it more obvious inside the IDE, ie without reading the documentation. 我将在FromFileUncached方法中添加一个[Obsolete]属性,因为它会使IDE内部更加明显,即无需阅读文档。

Can somebody please make clear what is the correct way to: 有人可以说明正确的方法是什么:

FromFile[Uncached] does not cache, FromBundle does. FromFile[Uncached]不缓存, FromBundle确实如此。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM