2015-07-21 53 views
0

編輯:我得到了一個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的論點,但仍然無法學到任何東西。

是否有人知道我還能如何調試以找出問題?或者更好的是,有誰看到這個問題,並知道我的問題是什麼?

+0

不停的問,在這裏,傻了。 –

+0

我問開發論壇,沒有迴應。相當絕望,撞上了一堵磚牆:「如果有人看到這個,也不會傷害到它。我認爲我沒有違反任何SO規則,即使這個問題不可回答 –

回答

0

只是需要加入這一行:

//`bounds` calculated from the size of the image 
//mainLayerContext and flatCache defined above in question ^^ 
CGContextDrawLayerInRect(mainLayerContext, bounds, _flatCache); 

在最後

相關問題