- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当将位图数据写入 bitmapImageRep 时,[NSView cacheDisplayInRect:(NSRect)rect toBitmapImageRep:(NSBitmapImageRep *)bitmapImageRep]
如何在内部工作?
例如它是遍历并访问所有 subview 的 CALayer 层
并在调用 ...cacheDisplayInRect...
时组合它们还是简单地编写它自己的层(然后已经包含所有 subview 的表示数据)。
我的问题的背景:我使用的本地控件 (WKWebView) 在屏幕截图 ( example SO question ) 时被破坏了,而不是重新发明轮子来截取整个屏幕截图应用程序包括 WKWebView 我想修复 Cocoa 用于位图表示的方法。
最佳答案
我做了一些试验和错误,发现 ...cacheDisplayInRect... 和 ...drawInContext... 调用 - [NSView drawRect:] 在内部渲染元素。
#0 0x000000010000e28c in -[DXSecureWKWebView drawRect:] at /Users/x/dev/X/XSecureWKWebView.m:34
#1 0x00007fff8d386749 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#2 0x00007fff8d386afe in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#3 0x00007fff8d386afe in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#4 0x00007fff8d386168 in __46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke ()
#5 0x00007fff8d385e11 in -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] ()
#6 0x00007fff8d385493 in -[NSView(NSLayerKitGlue) drawLayer:inContext:] ()
#0 0x000000010000e2dc in -[XSecureWKWebView drawRect:] at /Users/x/dev/x/XSecureWKWebView.m:34
#1 0x00007fff8d386749 in -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] ()
#2 0x00007fff8d65fe1c in __50-[_NSViewBackingLayer _renderForegroundInContext:]_block_invoke ()
#3 0x00007fff8d385e11 in -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] ()
#4 0x00007fff8d50b740 in -[_NSViewBackingLayer _renderForegroundInContext:] ()
#5 0x00007fff934f5ce1 in -[CALayer renderInContext:] ()
#6 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#7 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#8 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#9 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#10 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#11 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#12 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#13 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#14 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#15 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#16 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#17 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#18 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#19 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#20 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#21 0x00007fff934f7aaf in -[CALayer _renderSublayersInContext:] ()
#22 0x00007fff8d50b807 in -[_NSViewBackingLayer _renderSublayersInContext:] ()
#23 0x00007fff934f5cf0 in -[CALayer renderInContext:] ()
#24 0x00007fff8d50b11d in -[NSView _layerBackedDisplayRectIgnoringOpacity:inContext:isRootView:flipContextIfNeedeed:] ()
#25 0x00007fff8d50ac74 in -[NSView displayRectIgnoringOpacity:inContext:] ()
#26 0x00007fff8d65f685 in __62-[NSView cacheDisplayInRect:toBitmapImageRep:includeSubviews:]_block_invoke ()
#27 0x00007fff8d65f3dc in __36-[NSBitmapImageRep _captureDrawing:]_block_invoke ()
#28 0x00007fff8d65f14c in -[NSBitmapImageRep _captureDrawing:] ()
#29 0x00007fff8d65f079 in -[NSView cacheDisplayInRect:toBitmapImageRep:includeSubviews:] ()
关于objective-c - cacheDisplayInRect 在内部是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34066859/
当将位图数据写入 bitmapImageRep 时,[NSView cacheDisplayInRect:(NSRect)rect toBitmapImageRep:(NSBitmapImageRep
我尝试制作 WKWebView 是 OS X 应用程序的屏幕截图,并得到完全空白的屏幕截图。此代码适用于原始 WebView,但不适用于 WKWebView。 NSView *view = webVi
我正在处理图像的应用程序。这就像用户最多放置 4 张图像并根据用户选择的模板对它们进行布局。一张图片在最终 View 中可能会添加 2-3 次。 布局中的每个图像都是在 NSView 中绘制的(NSV
您好!我遇到了问题,谷歌搜索没有结果... 我为我的 NSView (子类)实现了 drawRect 方法来绘制一些阴影和半透明填充。一切看起来都很棒!但现在我需要从 NSView 创建一个 NSIm
我是一名优秀的程序员,十分优秀!