0

如何获取捕获图像设备上的路径?我正在显示图像,下面我有开关,何时关闭我显示项目的默认图像,何时打开我想显示用户捕获的图像。在捕获功能中,我可以将图像设置为我的 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>";
}

但我找不到任何可以用来寻找路径的东西。如何找到图像的路径,以便稍后重新加载相同的图像?

4

2 回答 2

0

我认为您找不到捕获图像的路径,因为如果您从代码中捕获图像,iPhone 不会将其保存到文件中。在我看来,你有两种方法:

1)您可以创建一个单例类来记住变量中的 UIImage ,然后可以访问它。

2)您可以将捕获的图像保存到缓存文件夹中的文件,然后获取它的路径;

于 2013-05-14T08:01:51.013 回答
0

如果您想在应用程序的后期阶段使用此图像,则必须保存图像的 URL。

如果要提取图像 URL 和图像名称,可以在当前实现的委托方法中自行完成。该NSDictionary信息包含有关图像的所有信息。

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker  didFinishPickingMediaWithInfo:(NSDictionary *)info{

    NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
    NSString *imageName = [imagePath lastPathComponent];
}

您可以imagePath在此阶段使用保存图像didFinishPickingMediaWithInfo:

于 2013-05-14T03:55:57.317 回答