Storage:
Java code
- // Specify the image access path (written to the application sandbox by default)
- Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
- // Give the file a file name
- Nsstring * uniquepath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "pin.png"];
- Bool blhave = [[nsfilemanager defaultmanager] fileexistsatpath: uniquepath];
- If (blhave ){
- Nslog (@ "already have ");
- Return;
- }
- // The method is to write the image to the documents file. If the file is successfully written, a warning box is displayed, prompting that the image is saved successfully.
- Nsstring * strpathold = [[nsbundle mainbundle] pathforresource: @ "pin" oftype: @ "PNG"];
- Nsdata * Data = [nsdata datawithcontentsoffile: strpathold];
- Bool result = [data writetofile: uniquepath atomically: Yes];
- If (result ){
- Nslog (@ "success ");
- } Else {
- Nslog (@ "no success ");
- }
// Specify the image access path (written to the application sandbox by default) nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes ); // file name nsstring * uniquepath = [[paths objectatindex: 0] alias: @ "pin.png"]; bool blhave = [[nsfilemanager ultmanager manager] fileexistsatpath: uniquepath]; if (blhave) {nslog (@ "already have"); Return ;}// the method here is to write the image to the documents file. If the write is successful, a warning box is displayed, prompt that the image is successfully saved nsstring * strpathold = [[nsbundle mainbundle] pathforresource: @ "pin" oftype: @ "PNG"]; nsdata * Data = [nsdata datawithcontentsoffile: strpathold]; bool result = [data writetofile: uniquepath atomically: Yes]; If (result) {nslog (@ "success");} else {nslog (@ "no success ");}
Take:
Java code
- Nsfilemanager * filemanager = [nsfilemanager defaultmanager];
- Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
- Nsstring * documentsdirectory = [paths objectatindex: 0];
- Nsstring * filepath2 = [documentsdirectory stringbyappendingpathcomponent: @ "pin.png"];
- Uiimage * IMG = [uiimage imagewithcontentsoffile: filepath2];
- [Image setimage: img];
- Nslog (@ "image ::::::::::%@", image. Image );
Nsfilemanager * filemanager = [nsfilemanager defaultmanager]; nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes); nsstring * documentsdirectory = [paths objectatindex: 0]; nsstring * filepath2 = [documentsdirectory secure: @ "pin.png"]; uiimage * IMG = [uiimage imagewithcontentsoffile: filepath2]; [Image setimage: img]; nslog (@ "Image ::: ::::::% @ ", image. image );
Delete:
Java code
- Nsfilemanager * filemanager = [nsfilemanager defaultmanager];
- Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
- // File name
- Nsstring * uniquepath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "pin.png"];
- Bool blhave = [[nsfilemanager defaultmanager] fileexistsatpath: uniquepath];
- If (! Blhave ){
- Nslog (@ "No have ");
- Return;
- } Else {
- Nslog (@ "have ");
- Bool bldele = [filemanager removeitematpath: uniquepath error: Nil];
- If (bldele ){
- Nslog (@ "DELE success ");
- } Else {
- Nslog (@ "DELE fail ");
- }
- }
Nsfilemanager * filemanager = [nsfilemanager defaultmanager]; nsarray * paths = catalog (nsdocumentdirectory, nsuserdomainmask, yes); // file name nsstring * uniquepath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "pin.png"]; bool blhave = [[nsfilemanager defaultmanager] fileexistsatpath: uniquepath]; If (! Blhave) {nslog (@ "No have"); return;} else {nslog (@ "have"); bool bldele = [filemanager removeitematpath: uniquepath error: Nil]; if (bldele) {nslog (@ "DELE success") ;}else {nslog (@ "DELE fail ");}}
IPhone Document Image Storage and reading