Search code examples
iphoneobjective-cxcodeexif

Obtain Image path for CGImageSourceRef


Hey guys, i'm currently trying to get the EXIF data from an image selected by the user via the UIIMagePickerController. I can't seem to get my head around how I would obtain a path I can use for the CGImageSourceCreateWithURL((CFURLRef)someURL,nil).

When I try to use the UIImagePickerControllerReferenceURL the console spits out a rather nice error : <ERROR> CGImageSourceCreateWithURLCFURLCreateDataAndPropertiesFromResource failed with error code -11.. I'm stumped, I'm starting to think I'm coming from a whole wrong angle, since the CGImageSourceRef type is generally used to create an image, while I already have a UIImage. Anyone that can shed some light on this matter, please feel free to do so.

- (void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info {

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSLog(@"%@",[info objectForKey:UIImagePickerControllerReferenceURL]);
    //Outputs: assets-library://asset/asset.JPG?id=1000000006&ext=JPG
    CGImageSourceCreateWithURL((CFURLRef)[info objectForKey:UIImagePickerControllerReferenceURL], nil);

    //The plan is to somehow get a CGImageSourceRef object from the 
    //UIImage provided by the [info UIImagePickerControllerOriginalImage], i just don't know how to get this object,
    // for it requires the URL to the image, wich i don't seem to have.
    }

}

-Edit- Will use the workaround offered by more tension. Thanks for reading.


Solution

  • The error code -11 means the URL scheme is unrecognized, which is to say the CFURL doesn't know what to do with URLs beginning with assets-library://.

    Why do you think you need a CGImageSourceRef in this case?