2012-06-26 152 views
0

我從服務器獲取圖像的URL,並使用以下格式將此圖像轉換爲PNG格式: NSData * data1 = [NSData dataWithData:UIImagePNGRepresentation(img)]; [data1 writeToFile:pngFilePath atomically:YES];文檔目錄中損壞的圖像

但是當我在模擬器上完成該過程後檢查它們時,某些圖像已損壞。 因此,這些圖像不會在需要的應用程序上顯示。

請參閱附件圖像,因爲一些圖像已損壞。

enter image description here

更新

我打電話在一個循環中,其取出由服務器並行和didFinishLoading我執行該圖像的方法: 的UIImage * IMG = [UIImage的imageWithData:自我。數據];

NSArray *split = [self.strImageName componentsSeparatedByString:@"/"]; 

int arrCount=[split count]; 
NSString *imageName=[split objectAtIndex:arrCount-1]; 



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

NSString *pngFilePath=nil 
pngFilePath = [NSString stringWithFormat:@"%@/Thumbs/%@",docDirec,imageName]; 


NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(img)]; 
[data1 writeToFile:pngFilePath atomically:YES]; 

[self.data release]; //don't need this any more, its in the UIImageView now 
self.data=nil; 

回答

0

我有類似的問題 我解決它使用下面的代碼

- (void)viewWillDisappear:(BOOL)animated 
{ 



    if (self.m_objWebManager != nil)//Webmanager is class for downloading the images as a background thread 
    { 
     [self.m_objWebManager cancelCommunication]; 

     [self.m_objWebManager release]; 

     self.m_objWebManager = nil; 
    } 

}