2

I want to draw image with HardLight composite operation. I've created NSImageView with next draw code:

- (void)drawRect:(NSRect)dirtyRect {
//[super drawRect:dirtyRect];

if (self.image != NULL) {
    [self.image drawInRect:self.bounds fromRect:NSZeroRect operation:NSCompositeHardLight fraction:1.0];
}

}

In usual case it works well. But it does not work over NSVisualEffectView.

How can I blend HardLight over NSVisualEffectView?

in the image linked below you can see rounded rectangle which blend HardLight over window background and colour image. But over NSVisualEffectView (red bottom rectangle) it draws just grey.

https://www.dropbox.com/s/bcpe6vdha6xfc5t/Screenshot%202015-03-27%2000.32.53.png?dl=0

Vincenso
  • 516
  • 4
  • 8
  • Did you manage to solve this problem? I've got the same problem here http://stackoverflow.com/questions/33341763/transparent-window-with-visual-effects-that-affect-the-content-in-the-underlying and want to know if is possible.. – Grigory Oct 27 '15 at 10:12

1 Answers1

2

Roughly speaking, image compositing takes none, one or both pixels from the source and destination, applies some composite operation and writes it to the destination. To get any effect that takes into account the destination pixel, that pixel’s color information must be known when the compositing operation takes place, which is in your implementation of -drawRect:.

I’m assuming you’re talking about behind window blending (NSVisualEffectBlendingModeBehindWindow) here. The problem with NSVisualEffectView is that it does not draw anything. Instead, it defines a region that tells the WindowServer process to do its vibrancy stuff in that region. This happens after your app draws its views.

Therefore a compositing operation in your app cannot take into account the pixels that the window server draws later. In short, this cannot be done.

Marco Masser
  • 1,076
  • 1
  • 8
  • 14