スクリーンショットを撮り、そのローカルパスをwebviewに送信したいので、それが表示されます。webviewがNSBundleから画像を取得できることは知っていますが、このスクリーンショットは動的に作成されます-コードで何かを追加できますか?
私はこのようにそれを試していました:
UIGraphicsBeginImageContext( webView.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *file = @"myfile.png";
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *path = [directory stringByAppendingPathComponent: file];
[UIImagePNGRepresentation(viewImage) writeToFile:path atomically:YES];
NSString *function = [NSString stringWithFormat:@"loadImagePlease(%@);",path];
[ ad stringByEvaluatingJavaScriptFromString:function];
ただし、loadImageFunctionは、file:///またはfile://プレフィックスを使用してアクセスできません。解決策は何ですか?助けてくれてありがとう。
編集:コードに欠落している行を追加しました
解決策:Cyrilleのアドバイスとこのライブラリをエンコードに使用しました:http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html