1.
-(void)saveImage:(CGImageRef)image directoryURL:(NSURL*)directoryURL filename:(NSString*)filename {
@autoreleasepool {
NSURL *fileURL = [directoryURL URLByAppendingPathComponent:filename];
// fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directory, filename]];
CFURLRef url = (__bridge CFURLRef)fileURL;
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, image, nil);
if (!CGImageDestinationFinalize(destination))
NSLog(@"ERROR saving: %@", url);
CFRelease(destination);
// CGImageRelease(image);
NSLog(@"saveImage: %@", fileURL);
}
}
+ (UIImage *)imageWithColor:(UIColor *)color AndRect:(CGRect)rect{
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}