[英]not getting everything in a MacOS webview screenshot
wI am trying to capture a screenshot of a cocoa webview using this code: 我正在尝试使用以下代码捕获cocoa webview的屏幕截图:
NSBitmapImageRep *bitmapRepRight = [[webView mainFrame].frameView bitmapImageRepForCachingDisplayInRect:cacheRect];
[[[webView mainFrame].frameView documentView] layout];
[[webView mainFrame].frameView cacheDisplayInRect:cacheRect toBitmapImageRep:bitmapRepRight];
return [bitmapRepRight CGImage];
This code is called from the - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame function. 此代码从 - (void)webView:(WebView *)发送者didFinishLoadForFrame:(WebFrame *)框架函数调用。
I am only getting the background of the page but no text neither images. 我只获得页面的背景,但没有文字也没有图像。
If I call it using [self performSelector:@selector(addPagesToCache) withObject:nil afterDelay:0.01]; 如果我使用[self performSelector:@selector(addPagesToCache)withObject:nil afterDelay:0.01]调用它; then it works but this is not a clean way at all.
然后它工作,但这根本不是一个干净的方式。
What could be the issue and how can I fix it? 可能是什么问题,我该如何解决?
If your webview is visible (in a window), you could use CGWindowListCreateImage to take a partial image of the window. 如果您的webview可见(在窗口中),则可以使用CGWindowListCreateImage来获取窗口的部分图像。 This is also a workaround, not a perfect solution.
这也是一种解决方法,而不是一个完美的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.