zoukankan      html  css  js  c++  java
  • 将UIImage保存成JPG或PNG格式存储在本地

     1 -(void)pngAndJpg:(UIImage*)image{
     2     NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
     3     NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
     4     
     5     // Write a UIImage to JPEG with minimum compression (best quality)
     6     // The value 'image' must be a UIImage object
     7     // The value '1.0' represents image compression quality as value from 0.0 to 1.0
     8     [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];
     9     
    10     // Write image to PNG
    11     [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
    12     
    13     // Let's check to see if files were successfully written...
    14     
    15     // Create file manager
    16     NSError *error;
    17     NSFileManager *fileMgr = [NSFileManager defaultManager];
    18     
    19     // Point to Document directory
    20     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    21     
    22     // Write out the contents of home directory to console
    23     NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
    24     
    25 }
  • 相关阅读:
    洛谷 P1823 音乐会的等待
    [The Diary] 10.30 Monday
    洛谷 P1094 纪念品分组
    codevs 1258 关路灯
    NOIP 2012 国王游戏(60分)
    bzoj3745 [COCI2015]Norma
    CF1110E Magic Stones
    bzoj4237 稻草人
    bzoj2653 middle
    单调队列与斜率优化杂题
  • 原文地址:https://www.cnblogs.com/fearlessyyp/p/5590808.html
Copyright © 2011-2022 走看看