如何获取捕获图像的设备路径? 我正在显示图像,下面我关闭时切换我从项目显示默认图像,当我打开时我想显示用户捕获的图像。 在捕获功能中,我可以将图像设置为我的imageView
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:NULL];
NSLog(@"%@", info);
UIImage * imageTemp = [info objectForKey:UIImagePickerControllerEditedImage];
if (imageTemp == nil)
imageTemp = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.image setImage:imageTemp];
}
它将图像设置为imageview但我没有路径。我有打印信息,它看起来像
{
UIImagePickerControllerMediaMetadata = {
DPIHeight = 72;
DPIWidth = 72;
Orientation = 6;
"{Exif}" = {
ApertureValue = "2.526068811667588";
BrightnessValue = "5.667090406070278";
ColorSpace = 1;
DateTimeDigitized = "2013:05:14 01:02:48";
DateTimeOriginal = "2013:05:14 01:02:48";
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.008620689655172414";
FNumber = "2.4";
Flash = 25;
FocalLenIn35mmFilm = 35;
FocalLength = "4.28";
ISOSpeedRatings = (
50
);
MeteringMode = 5;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = "6.862622389675391";
SubjectArea = (
1631,
1223,
881,
881
);
WhiteBalance = 0;
};
"{TIFF}" = {
DateTime = "2013:05:14 01:02:48";
Make = Apple;
Model = "iPhone 4S";
Software = "6.1.3";
XResolution = 72;
YResolution = 72;
};
};
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x20ac0470>";
}
但我找不到任何可以用来寻找路径的东西。如何查找路径o图像,以便我可以再次重新加载相同的图像?
答案 0 :(得分:0)
如果您想在应用中的后续阶段使用此图片,则必须保存图片的网址。
如果要提取图像URL和图像名称,可以在当前实现的委托方法中自行完成。 NSDictionary
信息包含有关图像的所有信息。
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
}
您可以在imagePath
didFinishPickingMediaWithInfo:
保存图片
答案 1 :(得分:0)
我认为您无法找到捕获图像的路径,因为如果您从代码中捕获图像,iPhone就不会将其保存到文件中。 在我看来,你有两种方式:
1)您可以创建一个单例类来记住变量中的UIImage,并且可以访问它。
2)您可以将捕获的图像保存到缓存文件夹中的文件中,然后获取它的路径;