Rajkumar
Rajkumar

Reputation: 179

How to store an image as a profile pic of one user?

I'm beginner of iphone app development.I done an iphone app that it contains registration page,login page and profile using sql database as a saving field.I want to keep a pic as profile pic.I done selecting a pic from already stored pics from simulator.I want to keep that pic as it is when once again if I run that....plz help me...

Upvotes: 7

Views: 108

Answers (2)

Paresh Navadiya
Paresh Navadiya

Reputation: 38249

Use this when obtaining image of image selected from gallery by using 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];
   }

Similarly when retrieve image use documentDirectory+imageFile.png (which is obtained from database by querying user name with its imageFile) path to set user profile pic

Upvotes: 0

Rajkumar
Rajkumar

Reputation: 271

You can store the image in Application bundle and can retrieve the image at the time of application load:

Here is a tutorial for you :

http://www.friendlydeveloper.com/2010/02/using-nsfilemanager-to-save-an-image-to-or-loadremove-an-image-from-documents-directory-coding/

Upvotes: 2

Related Questions