第43月第10天 uiimage写文件

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;

}

https://www.cnblogs.com/piaojin/p/5066090.html

https://www.jianshu.com/p/942f974f5c30

原文地址:https://www.cnblogs.com/javastart/p/12671634.html