2014-01-20 14 views
1

我有一個MvvmCross項目,使用MvxImageViewLoader從後臺加載URL圖片。我使用DefaultImagePath來指定默認圖像,以防萬一URL不正確或根本沒有指定URL。MvxImageViewLoader默認圖片忽略視網膜資源

問題是此路徑忽略來自文件系統的視網膜圖像@2x並始終顯示非視網膜圖像。

這是代碼:

_imageLoader = new MvxImageViewLoader(() => ImageView) 
{ 
    // After loading the Image view, the scale of the image is always 1.0 
    DefaultImagePath = NSBundle.MainBundle.PathForResource("image", "png") 
}; 
// At this point, ImageView.Image.CurrentScale is 1.0 (WRONG) on retina devices 

其中ImageView是標準UIImageView

但加載從路徑直接按預期工作的形象:

// The scale of this image is 2.0 on retina devices (as expected) 
var image = UIImage.FromFile(NSBundle.MainBundle.PathForResource("image", "png")); 

作爲一種變通方法,我添加了這個條件命名:

var imageName = UIScreen.MainScreen.Scale > 1 ? "[email protected]" : "image"; 
_imageLoader = new MvxImageViewLoader(() => ImageView) 
{ 
    DefaultImagePath = NSBundle.MainBundle.PathForResource(imageName, "png") 
}; 
// At this point, ImageView.Image.CurrentScale is 2.0 on retina devices as expected 

但這並不考慮其他的命名規則例如用於iPad的~ipad和用於iPad視網膜的@2x~ipad。所以我想知道如果我做錯了什麼,或者它是MvvmCross插件,應該使用便捷的UIImage初始化方法。

看來,MvxTouchLocalFileImageLoaderalready uses UIImage.FromFile,所以我不知道爲什麼行爲是不同的。

編輯:這是一個downloadable sample project重現此問題。

謝謝。

+0

如果您只在應用程序的某些測試代碼中使用'UIImage.FromFile',它會正確拾取視網膜圖像嗎?如果不是,那麼首先嚐試解決這個問題 - 檢查構建操作,嘗試一個乾淨/重建等。如果測試代碼確實有效,那麼我現在就有點想法了。 – Stuart

+0

@Stuart第二段代碼就是這種情況,它按預期工作。 – redent84

+0

@Stuart增加了重現該問題的示例項目 – redent84

回答