ios - Save UIImageView image -


i have ability take photo or load camera , place image in uiimageview in app want ability have button save image when reload app image still in uiimageview.

my though button save image once have loaded , in

-(void)viewdidload 

have code load image saved don't know how approach this.

any fantastic.

you can convert images nsdata using either uiimagepngrepresentation or uiimagejpgrepresentation, save data file calling 1 of nsdata's writetofile... methods.

then when restart application, can image calling [uiimage imagewithdata:[nsdata datawithcontentsoffile:filepath]]

-- edit --

save image

uiimage *image = ...; nsstring *cachedfolderpath = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes)[0]; nsstring *cachedimagepath = [cachedfolderpath stringbyappendingpathcomponent:@"image.png"]; [uiimagepngrepresentation(image) writetofile:cachedimagepath atomically:yes]; 

load image

nsstring *cachedfolderpath = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes)[0]; nsstring *cachedimagepath = [cachedfolderpath stringbyappendingpathcomponent:@"image.png"]; uiimage *image = [uiimage imagewithdata:[nsdata datawithcontentsoffile:cachedimagepath]]; 

i used nscachesdirectory since i'm assuming don't want have image backed (either through icloud or itunes). if you'd want use nsdocumentdirectory instead.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -