zoukankan      html  css  js  c++  java
  • 保存为本地文件

    相关资料http://blog.sina.com.cn/s/blog_a843a8850101flo3.html
    http://blog.csdn.net/enuola/article/details/8076221
    http://carlme.blog.163.com/blog/static/1837163272012715173659/

    A data object containing the JPEG data, or nil if there was a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

    UIKIT_EXTERN  NSData * __nullable UIImagePNGRepresentation(UIImage * __nonnull image);                               // return image as PNG. May return nil if image has no CGImageRef or invalid bitmap format
    UIKIT_EXTERN  NSData * __nullable UIImageJPEGRepresentation(UIImage * __nonnull image, CGFloat compressionQuality);  // return image as JPEG. May return nil if image has no CGImageRef or invalid bitmap format. compression is 0(most)..1(least)
    
    项目中自定义的用来保存UIImage
    +(void)saveImageToDomainsWithDirectorystringByAppendingPathComponent:(NSString *)suffix WithImage:(UIImage *)image{
        //JEPG格式
        //压缩图片
         NSData *imagedata=UIImageJPEGRepresentation(image,1.0);
        //获取沙盒路径
        NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
        //获取documents路径
        NSString *documentsDirectory=[paths objectAtIndex:0];
        //添加文件名及后缀
        NSString *savedImagePath=[documentsDirectory stringByAppendingPathComponent:suffix];
        //写入文件
        [imagedata writeToFile:savedImagePath atomically:YES];
    }
    //取图片
    + (UIImage *)fetchImageWithDirectorystringByAppendingPathComponent:(NSString *)suffix{
    
    NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.png",NSHomeDirectory(),suffix];
    
    UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3];
    
    UIImageView* imageView3=[[UIImageView alloc]initWithImage:imgFromUrl3];
        return imageView3.image;
    }
    
    追寻最真
  • 相关阅读:
    [CF786B] Legacy
    [CF833B] The Bakery
    [JSOI2008] 最小生成树计数
    [SDOI2010] 外星千足虫
    [POJ1830] 开关问题
    [Luogu1365] WJMZBMR打osu! / Easy
    [Noip2016] 换教室
    [NOI2002] 荒岛野人
    [计蒜之道复赛 2018] 贝壳找房计数比赛
    [SDOI2014] 旅行
  • 原文地址:https://www.cnblogs.com/zhao-jie-li/p/5865738.html
Copyright © 2011-2022 走看看