Iphone 文档目录中损坏的图像

Iphone 文档目录中损坏的图像,iphone,directory,document,Iphone,Directory,Document,我正在从服务器获取图像的URL,并使用以下方法将这些图像转换为png格式: NSData*data1=[NSData dataWithData:UIImagePNGRepresentationimg]; [data1 writeToFile:pngFilePath原子性:是] 但当我在模拟器上完成这个过程后检查它们时,有些图像被破坏了。 因此,这些图像不会显示在需要的应用程序上 由于某些图像已损坏,请查看所附图像 更新 我在一个循环中调用一个方法,该方法并行地从服务器获取图像,并执行以下操作:

我正在从服务器获取图像的URL,并使用以下方法将这些图像转换为png格式: NSData*data1=[NSData dataWithData:UIImagePNGRepresentationimg]; [data1 writeToFile:pngFilePath原子性:是]

但当我在模拟器上完成这个过程后检查它们时,有些图像被破坏了。 因此,这些图像不会显示在需要的应用程序上

由于某些图像已损坏,请查看所附图像

更新

我在一个循环中调用一个方法,该方法并行地从服务器获取图像,并执行以下操作: 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;

我也有类似的问题 我用下面的代码解决了它

- (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;
    }

}