OZZIE
OZZIE

Reputation: 7348

Finding filepath of an UIImage in Objective-C

In my app you pick an image using UIImagePickerControllerDelegate, so I have an UIImage. Now I need the filepath of said image.

More about the app: I'm trying to modify/edit a selected PNG image. I need to be able to access each pixel of chosen image. I have found source code on how to access the pixels but the code relies on loading the image via filepath and I haven't found any way of using the UIImage instead. I've tried:

CGImageRef si = [imageView.image CGImage];
CGDataProviderRef src = CGImageGetDataProvider(si);
CGImageRef img = CGImageCreateWithPNGDataProvider(src, NULL, NO, kCGRenderingIntentDefault);

But that only gives me the error: ": CGDataProviderGetSize: size is too large for this function."

(See iPhone SDK: accessing indexed color PNG images )

Upvotes: 1

Views: 352

Answers (1)

progrmr
progrmr

Reputation: 77193

When the image is picked, your delegate gets a callback on imagePickerController:didFinishPickingMediaWithInfo: That call includes an info parameter which is a dictionary. One of the keys gives you the file URL. A file URL can be converted to a path using the path method.

Upvotes: 1

Related Questions