Skip to content

Instantly share code, notes, and snippets.

View applezqp's full-sized avatar

applezqp applezqp

View GitHub Profile
- (UIImage *)createGrayCopy:(UIImage *)source
{
CGSize imageSize = source.size;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
size_t bytesPerRow = 0;
bytesPerRow = imageSize.width * CGColorSpaceGetNumberOfComponents(colorspace);
CGContextRef context = CGBitmapContextCreate (NULL, imageSize.width, imageSize.height, CGImageGetBitsPerComponent(source.CGImage), bytesPerRow, colorspace, kCGBitmapAlphaInfoMask & kCGImageAlphaNone);
CGColorSpaceRelease(colorspace);
if (context == NULL) {
return nil;
- (CALayer *)shadowLayer
{
CALayer *shadowLayer = [CALayer layer];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"shadow.png"];
NSData *imageData = [NSData dataWithContentsOfFile:filePath];
UIImage *shadowImage;