简体   繁体   English

如何将图像保存到沙箱-iPhone SDK

[英]How do I save an image to the sandbox - iPhone SDK

I have pulled an image out of the UIImagePicker thingy, and I would like to temporarily save it to the sandbox environment, in either the documents folder, or some other similar equivalent. 我已经从UIImagePicker中拉出了一个图像,我想将其临时保存到沙箱环境中的文档文件夹或其他类似的文件夹中。 However, I do not know how to do this, please could someone help me? 但是,我不知道该怎么做,请有人帮我吗? Thanks 谢谢

At the moment the image is a UIImage 目前该图像是一个UIImage

Saving an image: 保存图像:

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

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

}

Loading an image 加载图像

-(UIImage)loadImage{

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

   UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
}
-(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];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM