编辑:我投了反对票,我只是想确保这是因为我没有问开发论坛(我做了,https://forums.developer.apple.com/thread/11593,但没有得到任何回应)。这对我们来说是一个相当大的问题,所以我认为最好把线放宽,也许有人可以帮忙。
我们有一个可在 10.10 中运行的应用程序,但在 10.11 中存在此问题。我们调用-drawRect
一个NSGraphicsContext
在NSImage
两个操作系统中正确设置的
但在 10.11 中,这NSImage
不会被绘制。
我很新手,但是我已经调试了很长时间才能到达现在的位置,而我只是卡住了。正在查看是否有人以前遇到过这种情况,或者知道为什么会这样。
以下是相关代码:(layer
对象是CGLayerRef
从方法传入此方法的a -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相同,空白图像具有正确的大小
不幸的是,最初编写此代码的人现在已经走了,而且我太新手了,无法在没有找到一本书并阅读它的情况下进行挖掘。
bgRect 不是问题,已经尝试过修改它。我也弄乱了-translate
论点,但仍然无法学到任何东西。
有谁知道我还能如何调试它以找到问题?或者更好的是,有没有人看到这个问题并知道我的问题是什么?