2012-07-05 174 views
1

我想創建一個兼容視網膜和非視網膜顯示器的應用程序。我正在使用高分辨率圖像,並讓操作系統縮小非視網膜顯示器的尺寸。質量差的UIImages

圖像被命名爲[email protected],我用相同的名稱加載。這可以工作,並且圖像在兩種設備類型上以相同的相對大小顯示。不幸的是,在非視網膜顯示器上調整大小的圖像的質量遠非理想。

self.navigationItem.rightBarButtonItem.image = [localAssets imageAtPath:@"content/home/[email protected]"]; 

+ (UIImage*)imageAtPath:(NSString*)path; 
{ 
    NSString* extension = [path pathExtension]; 
    path = [path stringByDeletingPathExtension]; 

    NSString* filePath = [[NSBundle mainBundle] pathForResource:[path lastPathComponent] 
                 ofType:extension 
                inDirectory:[path stringByDeletingLastPathComponent]]; 
    UIImage* theImage = [UIImage imageWithContentsOfFile:filePath]; 

    if(!theImage) 
    { 
     NSLog(@"Error no file found at %@", [path stringByAppendingPathExtension:extension]); 
    } 
    return theImage; 
} 

視網膜:

http://i.imgur.com/gmn1q.png

遺產:

enter image description here

+0

發佈您的代碼。 – coneybeare 2012-07-05 20:17:08

回答

2

如果你的圖片尺寸調整自己,並將其保存爲xxx.png和[email protected],那麼你可以使用它們作爲「xxx」,當使用Retina顯示器時,iOS會自動使用@ 2x版本。

+0

謝謝,我試圖避免浪費多餘的磁盤空間。它只是好像我在UIImage調用中丟失了一些東西,導致它在調整大小後看起來很糟糕。 – charliehorse55 2012-07-05 20:21:45

+0

由於您已經將視網膜大小的圖像存儲在您的應用中,因此非視網膜的圖像似乎不會佔用那麼多的額外空間......但我當然不知道您項目的細節。 – Macondo2Seattle 2012-07-05 20:25:32

+0

如果25%的磁盤空間超過50MB,則無法打開25%的磁盤空間。 – charliehorse55 2012-07-05 20:30:38