2011-08-14 66 views
0

我從Web服務器下載jpeg圖片並將其加載到UIImage。從文件保存和加載時UIImage顯示不同

如果我直接顯示在所述的UIImageView的UIImage,我看到正確的圖像。

但是,如果我緩存的圖像與到文件:[:atoimcally sFilePath:UIImageJPEGRepresentation(圖像,1.0F)將writeToFile YES] 並與加載:

image=[UIImage imageWithContentsOFile:sFilePath] 

and display this in the same UIImageView, I can see white stripes in the sides of the picture. 

再次,完全相同的UIImageView對象在其中具有相同的屬性設置。

這是爲什麼?

+1

你應該嘗試加載使用圖像編輯器,你已經被緩存到文件,看看是否條紋在寫入步驟引入或當你正在讀回。 –

回答

2

您可以簡單地將文件寫入您已從網絡加載的文件NSData,而無需通過UIImageJPEGRepresentation例程。

[dataObject writeToURL:fileURL atomically:YES]; 

和檢索

UIImage *image = [[UIImage alloc] initWithContentsOfFile:[fileURL path]]; 

這工作真的很好,我的應用程序。

+0

賓果之後的圖像文件。很簡單 :) – tex1001

相關問題