Replicate background flash of photo paper in cocoa

I am trying to replicate the screen flash effect in a mac cocoa application similar to the Photo Booth application.

A white layer is superimposed on the screen, and the brightness of the screen is very bright, and then down again.

Can someone give me some tips on how this can be replicated in Cocoa?

thanks

+4
source share
2 answers

I suggest using the CGDisplayFade API for Quartz Display Services. It is very easy to use and does not require β€œhacking” with fake full-screen windows or views.

See here: Service Guide for Quartz Screens

A simple implementation would look like this:

-(void)flashScreenUsingFlashColor:(NSColor *)flashColor inDuration:(NSTimeInterval)inDuration outDuration:(NSTimeInterval)outDuration{ CGDisplayFadeReservationToken fadeToken; NSColor *colorToUse = [flashColor colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; CGError error = CGAcquireDisplayFadeReservation (inDuration + outDuration, &fadeToken); if (error != kCGErrorSuccess){ NSLog(@"Error aquiring fade reservation. Will do nothing."); return; } CGDisplayFade (fadeToken, inDuration, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, colorToUse.redComponent, colorToUse.greenComponent, colorToUse.blueComponent, true); CGDisplayFade (fadeToken, outDuration, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal,colorToUse.redComponent, colorToUse.greenComponent, colorToUse.blueComponent, false); } 
+6
source

You can look at this tutorial to create a full-screen window. Just make it white and use Core Animation to fade it. For example: [[MyFullScreenWindow animator] setAlphaValue:0.0]; will disappear.

+1
source

Source: https://habr.com/ru/post/1334332/


All Articles