macOS Mojave - NSReadPixel не работает - PullRequest
       33

macOS Mojave - NSReadPixel не работает

0 голосов
/ 12 октября 2018

У меня есть подкласс NSImageView для переопределения mouseDown метода, чтобы получить цвет точки нажатия, и до сих пор он работал нормально на всех версиях ОС (до 10.13.x), но на 10.14 это не похожеработает, и я всегда получаю нулевой цвет при использовании NSReadPixel.Ниже мой код метода mouseDown.

- (void)mouseDown:(NSEvent *)theEvent{
if(!self.image)
    return;
NSPoint clickedPoint = theEvent.locationInWindow;
NSPoint pointInDocumentView = [self convertPoint:clickedPoint fromView:nil];
[self lockFocus];
NSColor* colorAtClickedPoint = NSReadPixel(pointInDocumentView);
[self unlockFocus];
if(colorAtClickedPoint){
    if(self.delegate){
       [self.delegate colourCodeDidChange:colorAtClickedPoint];
    }
}

}

Пожалуйста, помогите.

1 Ответ

0 голосов
/ 13 октября 2018

Этот метод устарел в 10.14.Вы можете использовать другие методы, такие как следующие.Надеюсь, у вас нет проблем с ответом.

- (void)mouseDown:(NSEvent *)theEvent{
            if(!self.image)
                return;
            NSPoint clickedPoint = theEvent.locationInWindow;

            NSPoint pointInDocumentView = [self convertPoint:clickedPoint fromView:nil];
            NSBitmapImageRep * bitmapImageRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
            [self cacheDisplayInRect:self.bounds toBitmapImageRep:bitmapImageRep];
            [self lockFocus];
              NSColor* colorAtClickedPoint  =  [bitmapImageRep colorAtX:pointInDocumentView.x y:pointInDocumentView.y];

            [self unlockFocus];
            if(colorAtClickedPoint){
                if(self.delegate){
                    [self.delegate colourCodeDidChange:colorAtClickedPoint];
                }
            }

        }
...