Last active
March 11, 2016 06:40
-
-
Save TomLiu/7635912 to your computer and use it in GitHub Desktop.
return a GaussianBlured NSImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSImage+Blur.h | |
// BlurView | |
// | |
// Created by 61 on 13-11-19. | |
// Copyright (c) 2013年 61. All rights reserved. | |
// | |
#import <Cocoa/Cocoa.h> | |
@interface NSImage (Blur) | |
- (NSImage *)gaussianBlurOfRadius:(CGFloat)radius; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSImage+Blur.m | |
// BlurView | |
// | |
// Created by 61 on 13-11-19. | |
// Copyright (c) 2013年 61. All rights reserved. | |
// | |
#import <QuartzCore/QuartzCore.h> | |
#import "NSImage+Blur.h" | |
@implementation NSImage (Blur) | |
- (NSImage *)gaussianBlurOfRadius:(CGFloat)radius | |
{ | |
NSScreen *mainScreen = [NSScreen mainScreen]; | |
NSRect screenFrame = mainScreen.frame; | |
NSImage *image = [self scaleToSize:screenFrame.size]; | |
[image lockFocus]; | |
CIImage *beginImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]]; | |
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:kCIInputImageKey, beginImage, @"inputRadius", @(radius), nil]; | |
CIImage *output = [filter valueForKey:@"outputImage"]; | |
NSRect rect = NSMakeRect(0, 0, NSWidth(screenFrame), NSHeight(screenFrame)); | |
NSRect sourceRect = NSMakeRect(0, 0, self.size.width, self.size.height); | |
[output drawInRect:rect fromRect:sourceRect operation:NSCompositeSourceOver fraction:1.0]; | |
[image unlockFocus]; | |
return image; | |
} | |
@end |
nicolas-miari
commented
Mar 11, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment