如何从iOS中的uiwebview中获取图像

这里我加载的内容以及在web视图中的图像,我想从web视图中的图像,并加载到imageview。

图像的url被接收,但图像没有加载到imageview

在这里我使用的代码从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); } } 

看一下这个。

 -(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; } 

示例代码: http : //dl.dropbox.com/u/51367042/ImageFromWebView.zip