1. Create a new project, drag out two ImageView and two button, and associate the code separately
Join in 2.button action
-(Ibaction) Save: (ID) Sender {
Nsarray *paths = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES);
NSString *filepath = [[Paths objectatindex:0] stringbyappendingpathcomponent:[nsstring stringwithformat:@ "Pic.png"]] ; Save the name of the file
UIImage *image1 = _myimagview1.image;
BOOL result=[uiimagepngrepresentation (Image1) Writetofile:filepath Atomically:yes];
if (result) {
NSLog (@ "Success");
}
}
-(Ibaction) read: (ID) Sender {
Nsarray *paths = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask, YES);
NSString *filepath = [[Paths objectatindex:0] stringbyappendingpathcomponent:[nsstring stringwithformat:@ "Pic.png"]] ; Save the name of the file
UIImage *img = [UIImage Imagewithcontentsoffile:filepath];
_myimageview2.image = img;
} 3. Test