Skip to content

Instantly share code, notes, and snippets.

@LeviSchuck
Created August 23, 2015 00:57
Show Gist options
  • Save LeviSchuck/d973f0b77c512076e0e2 to your computer and use it in GitHub Desktop.
Save LeviSchuck/d973f0b77c512076e0e2 to your computer and use it in GitHub Desktop.
//
// main.m
// ScreenSampleServ
//
// Created by Levi Schuck on 8/22/15.
// Copyright (c) 2015 Levi Schuck. All rights reserved.
//
#import <Foundation/Foundation.h>
@import CoreGraphics;
@import QuartzCore;
@import AppKit;
int main(int argc, const char * argv[]) {
@autoreleasepool {
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGImageRef screenshot = CGDisplayCreateImage(0);
CIImage * img = [CIImage imageWithCGImage:screenshot];
CIFilter * resize = [CIFilter filterWithName:@"CILanczosScaleTransform"];
[resize setValue:img forKey:kCIInputImageKey];
[resize setValue:[NSNumber numberWithFloat:1.0f] forKey:kCIInputAspectRatioKey];
[resize setValue:[NSNumber numberWithFloat:0.125] forKey:kCIInputScaleKey];
CIFilter * gaus = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaus setValue:resize.outputImage forKey:kCIInputImageKey];
[gaus setValue:[NSNumber numberWithFloat:10.0f] forKey:kCIInputRadiusKey];
CIImage * result = [gaus valueForKey:kCIOutputImageKey];
NSString * filePath = [@"~/Desktop/test.png" stringByExpandingTildeInPath];
NSBitmapImageRep* pngRep = [[NSBitmapImageRep alloc] initWithCIImage: result];
NSData *pngData = [pngRep representationUsingType: NSPNGFileType properties: nil];
[pngData writeToFile: filePath atomically: YES];
CGImageRelease(screenshot);
CGColorSpaceRelease(colorSpace);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment