How to get image from uiwebview in ios

here I downloaded the content as well as the images in the webview, I want to take the image from the webview and upload it to the image.

Image URL received but image not loading into image

here i am using code to take image from webview

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //Touch gestures below top bar should not make the page turn. //EDITED Check for only Tap here instead. if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { CGPoint touchPoint = [touch locationInView:self.view]; NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"]; NSLog(@"pageFlag tapbtnRight %d", pageFlag); if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y]; NSString *urlToSave = [webView stringByEvaluatingJavaScriptFromString:imgURL]; NSLog(@"urlToSave :%@",urlToSave); } } 
+4
source share
1 answer

Check this.

 -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { NSLog(@"TAPPED"); //Touch gestures below top bar should not make the page turn. //EDITED Check for only Tap here instead. if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { CGPoint touchPoint = [touch locationInView:self.view]; NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"]; NSLog(@"pageFlag tapbtnRight %d", pageFlag); if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y]; NSString *urlToSave = [webV stringByEvaluatingJavaScriptFromString:imgURL]; NSLog(@"urlToSave :%@",urlToSave); NSURL * imageURL = [NSURL URLWithString:urlToSave]; NSData * imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage * image = [UIImage imageWithData:imageData]; imgView.image = image;//imgView is the reference of UIImageView } } return YES; } 

Example code: http://dl.dropbox.com/u/51367042/ImageFromWebView.zip

+16
source

Source: https://habr.com/ru/post/1401379/


All Articles