在ios中的imageView中的path显示图像
我有图像path,我想在uiimageview中显示它,
/用户/ WTS-新build/库/开发商/ CoreSimulator /设备/ F43C 26D2-DCFF-4764-AAF0-F6CC7BCDCF5D /数据/有限公司ntainers /数据/方面的应用中/ 8E49D340-7CAC-4031-85BF -9E5C26A1E3 7A /文档/小米ario.png
我怎样才能让图像显示?
尝试使用下面的代码:
从图像名称获取图像path:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *imageFilePath; NSError *err; imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"Small-mario.png"];
使用imageWithContentsOfFile
方法设置图像:
YourImageView.image = [UIImage imageWithContentsOfFile: imageFilePath];
在设备上显示来自完整文件path的图像
NSString *path = @"<your file path>; NSURL *url = [NSURL fileURLWithPath:path]; NSData *data = [NSData dataWithContentsOfURL:url]; imageView.image = [UIImage imageWithData:data];