3

こんにちは、画像の保存に少し行き詰まっています。ジェスチャを作成してチュートリアルに従いましたが、実際に画像を保存する最後の部分に少し行き詰まっています。任意の助けをいただければ幸いです ここにチュートリアルのソースがあります

http://bees4honey.com/blog/tutorial/how-to-save-an-image-from-uiwebview/

前もって感謝します

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTouchesRequired = 2;
[self.myWebView addGestureRecognizer:doubleTap];


}

-(void) doubleTap :(UITapGestureRecognizer*) sender {
int scrollPositionY = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
int scrollPositionX = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.pageXOffset"] intValue];

int displayWidth = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.outerWidth"] intValue];
CGFloat scale = myWebView.frame.size.width / displayWidth;

CGPoint pt = [sender locationInView:self.myWebView];
pt.x *= scale;
pt.y *= scale;
pt.x += scrollPositionX;
pt.y += scrollPositionY;

NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", pt.x, pt.y];
NSString * tagName = [self.myWebView stringByEvaluatingJavaScriptFromString:js];

NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", startPoint.x, startPoint.y];
NSString *urlToSave = [self.myWebView stringByEvaluatingJavaScriptFromString:imgURL];


/// Stuck at this point to actually get the file

}

4

1 に答える 1

5
NSURL *url = [NSURL URLWithString:urlToSave];

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

UIImageWriteToSavedPhotosAlbum(image, <#id completionTarget#>, <#SEL completionSelector#>, <#void *contextInfo#>)

3 つのパラメーターすべてに nil を渡すことができます。だからあなたは呼び出すことができます

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
于 2012-12-07T22:18:47.033 に答える