【发布时间】:2012-06-26 20:51:47
【问题描述】:
我正在从服务器获取图像的 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;
【问题讨论】: