【问题标题】:How do I save an image to the sandbox - iPhone SDK如何将图像保存到沙箱 - iPhone SDK
【发布时间】:2011-10-16 14:34:34
【问题描述】:

我已经从 UIImagePicker 中提取了一个图像,我想将它临时保存到沙盒环境中,在文档文件夹或其他类似的文件夹中。但是,我不知道该怎么做,请有人帮助我吗?谢谢

目前图像是 UIImage

【问题讨论】:

标签: iphone image file save


【解决方案1】:

保存图片:

-(void)saveImage:(UIImage*)image{
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"];

   [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:YES];

}

加载图片

-(UIImage)loadImage{

   NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/someImageName.png"];

   UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
}

【讨论】:

    【解决方案2】:
    -(void)SaveImage
    
    {
    
    NSData *data;
    
    NSArray *paths;
    
    NSString *documentsDirectory,*imagePath ;
    
    UIImage *image=[UIImage imageNamed:@"public.png"];
    
     paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    documentsDirectory = [paths objectAtIndex:0];
    
    imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString   stringWithFormat:@"public.png"]];
    
    data = UIImagePNGRepresentation(image);
    
    [data writeToFile:imagePath atomically:YES];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-12
      • 2023-02-03
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 1970-01-01
      • 2018-05-28
      相关资源
      最近更新 更多