在iPhone中从UIImage将图像保存到沙箱中 [英] Save Image to sandbox from UIImage in iPhone

查看:121
本文介绍了在iPhone中从UIImage将图像保存到沙箱中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableView中显示非常大的图像,因此我的应用程序在一段时间后崩溃了。现在我想调整图像大小并将其保存到磁盘。有人可以帮助我调整NSData / UIImage中的图像大小并保存将其保存到磁盘。

I am showing very big size images in UITableView, because of this my app is getting crashed after some time. Now i want to resize the image and save it to disk. can some one help me resizing the image from NSData/UIImage and saving saving it to the disk.

我得到了从UIImage调整图像大小的代码,因此结果我在UIImage对象中调整了图像大小,如何将其保存到iphone沙箱。

I got the code to resize the image from UIImage, so as the result i have my resized in image in UIImage object, how to save it to iphone sandbox.

谢谢,

推荐答案

以下是保存到iOS上来自工作代码的Documents目录的代码。

Here is code to save to the Documents directory on iOS that is from working code.

// Convert UIImage to JPEG
NSData *imgData = UIImageJPEGRepresentation(image, 1); // 1 is compression quality

// Identify the home directory and file name    
NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"]; 

// Write the file.  Choose YES atomically to enforce an all or none write. Use the NO flag if partially written files are okay which can occur in cases of corruption
[imgData writeToFile:jpgPath atomically:YES]; 

这篇关于在iPhone中从UIImage将图像保存到沙箱中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆