简体   繁体   English

如何在iOS的某些文件输入字段上通过UIWebView中的UIImagePicker选择图像?

[英]How do I get image selected by UIImagePicker in UIWebView on certain file input field in iOS?

I am displaying html file in UIWebView which contains file input field. 我在包含文件输入字段的 UIWebView中显示html文件 When I click on file input field, it opens default UIImagePicker. 当我单击文件输入字段时,它将打开默认的UIImagePicker。 So I need image selected by that UIIMagePicker in iOS. 所以我需要由iOS中的UIIMagePicker选择的图像。

Please help me. 请帮我。 Thanks 谢谢

try to use this webview delegate method.i hope so it will help you. 尝试使用此webview委托method.i希望对您有帮助。

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

       //write your image picker code.
    }

You can load image from photolibrary to webview as shown in below 您可以将图像从图像库加载到webview ,如下所示

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info    
   {
  NSURL *urlPath = [info valueForKey:UIImagePickerControllerReferenceURL];
  UIImage *cameraImage = [info valueForKey:UIImagePickerControllerOriginalImage];
  NSData *myData = UIImagePNGRepresentation(cameraImage);
  [self.webview loadData:myData MIMEType:@"image/png" textEncodingName:nil baseURL:nil];
  [self.picker dismissViewControllerAnimated:YES completion:nil];
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM