イメージからイメージを取得したいのですが、パスから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;
}
かもしれませんか? –
パス*で参照されているデータが有効なjpegであるかどうかを確認しましたか? –
パスと画像が利用可能です – Gigi