Getting file path for UIImage

Discussion in 'iOS Programming' started by kobik, Jul 14, 2009.

  1. kobik macrumors newbie

    Joined:
    Jun 29, 2009
    #1
    Hi,

    My application uses UIImagePicker in order to let the user choose a photo from the photos collection.
    My application contains some pure C code which handles a photo.
    in order to operate my C code i need a path file to that selected image in order to pass this path to my C code (which uses fopen() in order to something with the file).
    so, my question is how do i get this file path in order to open it from my C code ?

    thanks a lot.
     
  2. isaaclimdc macrumors 6502

    isaaclimdc

    Joined:
    Jun 28, 2009
    Location:
    Pittsburgh, PA
    #2
    You could use:

    Code:
    - (void)viewDidLoad {
    	UIImage *imageVarName = [UIImage imageNamed:@"imageFileName.png"];
    then:
    Code:
    UIImageView *imageFileView = [[UIImageView alloc] initWithImage:imageVarName];
     
  3. kobik thread starter macrumors newbie

    Joined:
    Jun 29, 2009
    #3
    Hi,
    and thanks a lot for the reply,

    i might have not explained myself clearly -

    my situation is that the user finished selecting an image form his collection (using UIImagePickerCOntroller), than the application returns to my code in the UserDidFinishChoosingImage (i don't remember the name correctly), this routine gives me as a parameter the UIImage* selectedImage (i.e the image that the user sekected by touching an image from the photos coolection), so i don't realy know the image name, what i actaully need is to get the file path of the selected image (again - in order to use it later in C code with fopen() routine).
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I believe you should examine the UIImagePickerControllerMediaURL key in the info dictionary passed to imagePickerController:didFinishPickingMediaWithInfo:.

    UIImages to not contain the path for that image: there may be not path at all if the image has been created in memory and not saved to the filesystem. Note it is possible that this could happen and your C routine might have to deal with an image that does not exist on the filesystem. You might be better served dealing directly with the UIImage...
     
  5. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #5
    So, you want to find the file path to an arbitrary photo saved in the user's library?

    It might not be that simple. If the photo was somewhere in your own app bundle, that should be easy. Going across the file system. . . not so sure.

    I guess you could always copy the library image over to your app bundle's tmp directory, then find a path to that.
     
  6. kobik thread starter macrumors newbie

    Joined:
    Jun 29, 2009
    #6
    yeah...
    that was my thought also in case i won't be able to find the path.
    but, hey, since the UIImagePicker thing picks photos from the iphone photos library, doesn't this mean that all photos there are stored in the file system ?


    thanks a lot for all the answers.
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    No, you cannot make that assumption. The picker documents don't say this and I'd be pretty sure if the user takes a new picture instead of a saved one then this won't be saved anywhere on the filesystem and you will be passed a UIImage pointer to where it is in memory...
     
  8. kobik thread starter macrumors newbie

    Joined:
    Jun 29, 2009
    #8
    Thank you all for the quick answers.

    i guess i'll try the - save the image to my bandle for tmp use and later delete it.
    does anyone see any problem with that approach ?

    again,
    thanks a lot.
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    Yes: you can't write into your bundle :p You can write to your applications sandboxed filespace (outside of the app bundle) though.
     
  10. kobik thread starter macrumors newbie

    Joined:
    Jun 29, 2009
    #10
    ah... of caurse. my bad.
    anyway, it will let me the option to use the file path, right ?
     

Share This Page