objective c - iPhone Saving Images -


i have custom cell thumbnail image, user can select photo albums. know saving images core data result in poor performance, , should use file system.

anyone recommend tutorials on this. should store in core data, if not storing image there.

i storing larger image well, not thumbnail.

uiimage*image = [uiimage imagenamed:@"the image wish save.jpg"];  //build path image on filesystem nsarray *dirpath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *docsdir = [dirpath objectatindex:0]; nsstring* photoname = @"imagename.jpg"; nsstring *photopath = [docsdir stringbyappendingpathcomponent:photoname];  //get imagedata uiimage float imagecompression = 0.5; nsdata *imagedata = uiimagejpegrepresentation(image, imagecompression);  //save image                   if(![imagedata writetofile:path atomically:yes]){     return false; }  //store imagepath model photomodal.filepathimage = photopath; 

tips:

  • avoid duplicate names don't override exisitng files (don't worry you'll warning)
  • remember delete photo when model being deleted
  • build logical path , folder structure matches model, e.g - album.photo should have folder named album , in should store files, helps when delete album model

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -