Tôi không thể hiển thị hình ảnh (.png) của mình.Tải hình ảnh từ thư mục tài liệu
Tôi kiểm tra xem nó có tồn tại ở đường dẫn tôi sử dụng hay không. Nhưng không có hình ảnh nào xuất hiện.
Dưới đây là những gì tôi đã cố gắng:
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *outputPath = [documentsDir stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
NSString *imgPath = [[outputPath stringByReplacingOccurrencesOfString:@"mov" withString:@"png"]retain];
if ([fileManager fileExistsAtPath:imgPath])
{
NSLog(@"FOUND IMG");
NSLog(imgPath);
}
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPath]];
UIImage *thumbNail = [[UIImage alloc] initWithData:imgData];
UIImageView * imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
[imgView setImage:thumbNail];
[cell addSubview:imgView];
[imgView release];
Sản lượng debug xác nhận tập tin tồn tại
FOUND IMG
2011-12-26 12:42:23.066 iGeo2[412:707] /var/mobile/Applications/1A2B0D85-CDB1-4E4B-
9509-EF68B1A0E720/Documents/0.009000.png
Tôi là một chút bối rối. Có ai thấy tôi đã phạm sai lầm không?
Nhiều Cảm ơn, -Code
Tôi đã thử một vài phương pháp khác, nhưng không bao giờ xuất hiện.
Bạn có thể nhận được câu trả lời của bạn ở đây: http://stackoverflow.com/questions/6663511/iphone-how-to-display-document-directory-images-in- image-view – utsabiem
Để sử dụng 'NSFileManager', sử dụng đơn giản phương thức thuyết phục:' NSFileManager * fileManager = [NSFileManager defaultManager] 'Nói chung, hãy kiểm tra tài liệu cho các phương thức thuyết phục dựa trên lớp. Alss sử dụng ARC nếu có thể, nó thực sự aces phát triển mã đơn giản hơn nhiều. – zaph