如何将图像存储为一位用户的个人资料图片?
问题描述:
我是iphone应用程序开发的初学者。我做了一个iphone应用程序,它包含注册页面,登录页面和使用sql数据库作为保存字段的配置文件。我想保留一个图片作为配置文件pic.I完成从已经从模拟器中存储图片。我想保留这张照片,因为它再次如果我运行.... plz帮助我...如何将图像存储为一位用户的个人资料图片?
答
您可以将图像存储在应用程序包中,并可以检索图像在应用负载的时间:
这是给你一个教程:
答
使用通过使用imagepicker从库中选择图像的该获得的图像时:
-(void)saveImageInDirectoryAndStoreInDatabase
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *imgFilePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",youruserName];
NSData *data = UIImagePNGRepresentation(youruserImage) //which is obtained from imagepicker
[data writeToFile:imgFilePath atomically:YES];
//query here into database with imageFile(A string) which is[NSString stringWithFormat:@"%@.png",youruserName];
}
类似地,当检索图像使用documentDirectory + imageFile.png路径设定方法(这是从数据库通过用其镜像文件查询用户名获得)用户配置文件图片
您的图片不会改变,所以为什么不存储特定名称的名称,以及何时再次加载详细信息时,请使用该图像名称来显示图像。 –