Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kobik

macrumors newbie
Original poster
Jun 29, 2009
9
0
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.
 
You could use:

Code:
- (void)viewDidLoad {
	UIImage *imageVarName = [UIImage imageNamed:@"imageFileName.png"];

then:
Code:
UIImageView *imageFileView = [[UIImageView alloc] initWithImage:imageVarName];
 
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).
 
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...
 
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).

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.
 
I guess you could always copy the library image over to your app bundle's tmp directory, then find a path to that.

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.
 
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 ?

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...
 
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.
 
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.

Yes: you can't write into your bundle :p You can write to your applications sandboxed filespace (outside of the app bundle) though.
 
Yes: you can't write into your bundle :p You can write to your applications sandboxed filespace (outside of the app bundle) though.

ah... of caurse. my bad.
anyway, it will let me the option to use the file path, right ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.