编辑:我得到了一个downvote,我只是想确保这是因为我没有问开发论坛(我做的,https://forums.developer.apple.com/thread/11593,但没有得到任何回应)。这对我们来说是一个相当大的问题,所以我认为最好是投出一条广泛的线,也许有人可以提供帮助。`-drawInRect`在10.11中似乎有所不同?什么可以改变?
我们有一个应用程序在10.10中工作,但在10.11中有此问题。 我们对正确地在两个操作系统
设置但在10.11这个NSImage
没有拿得出的NSImage
调用在NSGraphicsContext
-drawRect
。
我是新手,但我已经调试了很长一段时间,以达到我现在所在的位置,而我只是普通卡住了。看到有人遇到过这个,或者有任何想法,为什么会这样。
下面是相关的代码: (该layer
对象是传入此方法一个CGLayerRef
,从-drawRect
方法) 这里是层如何实例:
NSRect scaledRect = [Helpers scaleRect:rect byScale:[self backingScaleFactorRelativeToZoom]];
CGSize size = NSSizeToCGSize(rect.size);
size_t width = size.width;
size_t height = size.height;
size_t bitsPerComponent = 8;
size_t bytesPerRow = (width * 4+ 0x0000000F) & ~0x0000000F;/
size_t dataSize = bytesPerRow * height;
void* data = calloc(1, dataSize);
CGColorSpaceRef colorspace = [[[_imageController document] captureColorSpace] CGColorSpace];
CGContextRef bitmapContext = CGBitmapContextCreate(data, width, height, bitsPerComponent, bytesPerRow, colorspace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
CGLayerRef canvasLayer = CGLayerCreateWithContext(bitmapContext, scaledRect.size, NULL);
这里是方法绘制图像:
CGContextRef mainLayerContext = CGLayerGetContext(layer);
NSRect scaledBounds = [contextInfo[kContextInfoBounds] rectValue];
if(!_flatCache)
{
_flatCache = CGLayerCreateWithContext(mainLayerContext, scaledBounds.size, NULL);
CGContextRef flatCacheCtx = CGLayerGetContext(_flatCache);
CGLayerRef tempLayer = CGLayerCreateWithContext(flatCacheCtx, scaledBounds.size, NULL);
CIImage *tempImage = [CIImage imageWithCGLayer:tempLayer];
NSLog(@"%@",tempImage);
CGContextRef tempLayerCtx = CGLayerGetContext(tempLayer);
CGContextTranslateCTM(tempLayerCtx, -scaledBounds.origin.x, -scaledBounds.origin.y);
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphicsPort:tempLayerCtx flipped:NO];
[NSGraphicsContext setCurrentContext:newContext];
if ([_imageController background])
{
NSRect bgRect = { [_imageController backgroundPosition], [_imageController backgroundSize] };
bgRect = [Helpers scaleRect:bgRect byScale:[self backingScaleFactorRelativeToZoom]];
[[_imageController background] drawInRect:bgRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
CIImage *tempImage2 = [CIImage imageWithCGLayer:tempLayer];
NSLog(@"%@",tempImage2);
在10.10和10.11,tempImage是一个空的图像瓦特/正确的尺寸。
在10.10 tempImage2现在有[_imageController background]
正确绘制
在10.11 tempImage2相同tempImage,空白图像W /尺寸正确
不幸的是谁最初写这个代码,现在走了的人,而且我太新手了,无法找到一本书并阅读它。
bgRect不是问题,已经尝试过修改该问题。我也搞砸了-translate
的论点,但仍然无法学到任何东西。
是否有人知道我还能如何调试以找出问题?或者更好的是,有谁看到这个问题,并知道我的问题是什么?
不停的问,在这里,傻了。 –
我问开发论坛,没有回应。相当绝望,撞上了一堵砖墙:“如果有人看到这个,也不会伤害到它。我认为我没有违反任何SO规则,即使这个问题不可回答 –