如何将图片从照片存储添加到UIWebview [英] how to add a image from the photo storage to a UIWebview

查看:126
本文介绍了如何将图片从照片存储添加到UIWebview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何都要在iphone照片存储的UIWebview中显示图像

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

推荐答案

可能这是合适的代码在上传图片中,

May be this is the suitable code in the upload image,

- (BOOL)webView:(UIWebView*)webViewRef shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    //we are listening out for links being click
    if (navigationType == UIWebViewNavigationTypeLinkClicked) 
    {

        NSURL *URL = [request URL]; //Get the URL


        if ( [[URL scheme] isEqualToString:@"objc"] ) {


            webView = webViewRef;


            SEL method = NSSelectorFromString( [URL host] );

            if ([self respondsToSelector:method])
            {

                [self performSelector:method withObject:nil afterDelay:0.1f];
            }

            return NO;
        }

    }

   return YES;
}
-(void)takePicture
{

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;


    id delegate = [[UIApplication sharedApplication] delegate];
    [[delegate viewController] presentModalViewController:imagePicker animated:YES];

    [imagePicker release];

}

#pragma mark - Image Picker

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

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];


    NSData *flatImage = UIImageJPEGRepresentation(image, 0.1f);



    NSString *image64 = [flatImage base64EncodedString];


    NSString *js = [NSString stringWithFormat: @"processImage('data:image/jpeg;base64,%@')", image64];
    [webView stringByEvaluatingJavaScriptFromString:js];


    [picker dismissModalViewControllerAnimated:YES];

}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {


    [picker dismissModalViewControllerAnimated:YES];
}

这篇关于如何将图片从照片存储添加到UIWebview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆