zoukankan      html  css  js  c++  java
  • 2016-03-09 保存图片

    下面介绍我最后使用的一个办法。

    先把图片直接存储到沙盒中。 然后plist文件中记录图片的路径。然后要使用图片的时候通过访问plist文件获取图片路径来调用。

    下面是使用示例:

    一。图片存储到沙盒中

     

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

            NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", myI]];   // 保存文件的名称

            [UIImagePNGRepresentation(myImage) writeToFile: filePath    atomically:YES];

     

    二。在plist中保存路径

     

     

    NSMutableDictionary *info = [[NSMutableDictionary alloc]init];

     

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

     

    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", conut_]];   // 保存文件的名称

     

    [info setObject:filePath forKey:@"img"];

    [specialArr addObject:info];

     

    三。使用图片

     

     

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", (int)current]];   // 保存文件的名称

    UIImage *img = [UIImage imageWithContentsOfFile:filePath];

  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5256937.html
Copyright © 2011-2022 走看看