【问题标题】:Corrupted Images in document directory文档目录中损坏的图像
【发布时间】: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;

【问题讨论】:

    标签: iphone directory document


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-30
      • 2016-09-30
      • 1970-01-01
      • 2017-05-25
      • 2017-12-29
      • 1970-01-01
      • 2014-02-11
      • 2013-07-16
      相关资源
      最近更新 更多