views:

52

answers:

2

Is there anyway to display a image in a UIWebview from the iphone photo storage

A: 

Yes, you first must use the UIImagePickerController. It will cause a new window from the iPhone to appear and the user will be requested to pick a photo.

When they pick the photo, you can get access to this photo, you can either dismiss the picker or the user can continue picking photos.

You are not allowed direct access to users photos and wont be able to access their photos with asking the user first. This makes total sense, as a user I would not want developers sneaking into my photo library and uploading my photos in the background.

To add these to a UIWebView, you will nee to set the [UIWebView basePath] to your (document directory where you saved the photo from the above process), I have got this working, search stackoverflow for UIWebView Basepath, or check documentation.

Cheers, John.

John Ballinger
Have u got a working example of this method I can have a look at.
How2iphone
Could not find anything on uiwebview basepath.have u got a working example I could have a look at.
How2iphone
+1  A: 

in your image picker delegate, save the file locally, basic code snippet, not complete

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

        NSString *path = [[NSBundle mainBundle] bundlePath];
        NSData *data = UIImageJPEGRepresentation( [info objectForKey:@"UIImagePickerControllerOriginalImage"] , 1.0);
        NSString *fullPath = [path stringByAppendingPathComponent:@"image_tmp.jpg"];
        if ([[NSFileManager defaultManager] createFileAtPath:fullPath contents:data attributes:nil] ) {
                    NSLog([NSString stringWithFormat:@"file successfully written to path %@",fullPath],nil);
        }
 }

the in your webview, set the base path of the HTML page you are going to load to the same path used for saving the image file.

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];
Aaron Saunders