2016-09-06 11 views
-1

イメージからイメージを取得したいのですが、パスからimageWithContentsOfFileを使用しますが、nilを返します。imageWithDataを試してみましたが、nilは返されません。 、どうもありがとうございました、私を助けてください! 「/var/mobile/Containers/Data/Application/F865E931-B673-4295-8AC3-B5C3560A10D6/Library/Caches/pic/0513041abff0edbb0e909a1364abe2ed.jpg」 ようなパスをところで、シミュレータ上では、このような状況にはならず、実際のマシンでのみnil caseを返します。imageWithContentsOfFile return nilそしてimageWithDataはnilを返します。

NSString * strDestinationPath = [[mainKeepData getPicturesPath] stringByAppendingString:imageName]; 
NSFileManager * fileManager = [NSFileManager defaultManager]; 
     BOOL bl1 = [fileManager fileExistsAtPath:strDestinationPath]; 
     if (bl1 == NO) 
     { 
      [request setDownloadDestinationPath:strDestinationPath]; 
      [request setCompletionBlock:^(void){ 
       UIImage * image=[UIImage imageWithContentsOfFile:strDestinationPath]; 
       [PictureDict setValue:image forKey:strGUID]; 
       [self.delegate DownloadPictureIsOver:YES RequestID:RequetID]; 
      }]; 

      [request setUserInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@",strGUID] forKey:@"name"]]; 
      [networkQueue addOperation:request]; 
     } 
     else 
     { 
      NSData *imageData = [NSData dataWithContentsOfFile:strDestinationPath]; 
      UIImage *image = [UIImage imageWithData:imageData]; 
      [PictureDict setValue:image forKey:strGUID]; 
     } 

パス機能

+(NSString *)getPicturesPath 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
    NSString *cachesDir = [paths objectAtIndex:0]; 

    NSString *filePath = [cachesDir stringByAppendingPathComponent:@"/pic/"]; 
    filePath=[filePath stringByAppendingString:@"/"]; 
    return filePath; 
} 
+0

かもしれませんか? –

+0

パス*で参照されているデータが有効なjpegであるかどうかを確認しましたか? –

+0

パスと画像が利用可能です – Gigi

答えて

0

はこれを試すことができます、あなたを助ける

NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"/pic/"]; 

return stringPath; 

// If you want particular image path 
stringPath = [stringPath stringByAppendingPathComponent:@"Your Img Name"]; 
UIImage *image = [UIImage imageWithContentsOfFile:stringPath]; 

コーディングハッピー... strDestinationPathを取得しているためにどのよう

+0

sailendraクマール、ありがとうございます。まだ画像はありません – Gigi

+0

@ Seven Wangは特定の画像を探していますか? –

+0

sailendra kumarはい – Gigi

関連する問題