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 }
  • 相关阅读:
    369. Plus One Linked List
    147. Insertion Sort List
    817. Linked List Components
    61. Rotate List
    Object 类
    多态
    重写方法
    Protected 修饰符
    继承
    数组
  • 原文地址:https://www.cnblogs.com/fearlessyyp/p/5590808.html
Copyright © 2011-2022 走看看