我从服务器获取图像的URL并使用以下方法将此图像转换为png格式: NSData * data1 = [NSData dataWithData:UIImagePNGRepresentation(img)]; [data1 writeToFile:pngFilePath atomically:YES];
但是当我在模拟器上完成该过程后检查它们时,某些图像已损坏。 因此,无论何时需要,这些图像都不会显示在应用程序上。
请参阅附图,因为有些图像已损坏。
更新
我在一个循环中调用一个方法,它从服务器并行获取图像并且didFinishLoading我正在执行此操作: UIImage * img = [UIImage imageWithData:self.data];
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 :(得分: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;
}
}