码迷,mamicode.com
首页 > 其他好文 > 详细

第43月第10天 uiimage写文件

时间:2020-04-10 10:29:59      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:component   style   app   nsurl   filename   uiimage   nil   tin   ryu   

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

 

第43月第10天 uiimage写文件

标签:component   style   app   nsurl   filename   uiimage   nil   tin   ryu   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!