zoukankan      html  css  js  c++  java
  • 把UIImage保存到照片库和沙盒中

    1、保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:

    .h文件

    #import <QuartzCore/QuartzCore.h>
    UIImageView *imageView;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    .m文件
    UIGraphicsBeginImageContext(imageView.bounds.size);
    [imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(temp, nil, nil, nil);

    2、保存到对应的沙盒目录中,具体代码如下:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"sms.gif"]];   // 保存文件的名称
    BOOL result = [UIImagePNGRepresentation(imageView.image)writeToFile: filePath atomically:YES]; // 保存成功会返回YES 
  • 相关阅读:
    20200807日报
    20200806日报
    《大道至简》读书感悟
    20200805日报
    20200804日报
    20200803日报
    20200802日报
    vue中mounted内如何调完异步方法再渲染
    小程序画布识别iPhone11
    np.meshgrid() 生成网格坐标函数
  • 原文地址:https://www.cnblogs.com/pengyunjing/p/5988955.html
Copyright © 2011-2022 走看看