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

发布于 2024-11-27 06:28:16 字数 121 浏览 0 评论 0原文

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

目前图像是 UIImage

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. However, I do not know how to do this, please could someone help me? Thanks

At the moment the image is a UIImage

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷弦 2024-12-04 06:28:16

保存图像:

-(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];
}

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];
}
顾铮苏瑾 2024-12-04 06:28:16
-(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];

}
-(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];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文