IPhone Document Image Storage and reading

Source: Internet
Author: User

Storage:

Java code
  1. // Specify the image access path (written to the application sandbox by default)
  2. Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
  3. // Give the file a file name
  4. Nsstring * uniquepath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "pin.png"];
  5. Bool blhave = [[nsfilemanager defaultmanager] fileexistsatpath: uniquepath];
  6. If (blhave ){
  7. Nslog (@ "already have ");
  8. Return;
  9. }
  10. // 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.
  11. Nsstring * strpathold = [[nsbundle mainbundle] pathforresource: @ "pin" oftype: @ "PNG"];
  12. Nsdata * Data = [nsdata datawithcontentsoffile: strpathold];
  13. Bool result = [data writetofile: uniquepath atomically: Yes];
  14. If (result ){
  15. Nslog (@ "success ");
  16. } Else {
  17. Nslog (@ "no success ");
  18. }
// 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
  1. Nsfilemanager * filemanager = [nsfilemanager defaultmanager];
  2. Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
  3. Nsstring * documentsdirectory = [paths objectatindex: 0];
  4. Nsstring * filepath2 = [documentsdirectory stringbyappendingpathcomponent: @ "pin.png"];
  5. Uiimage * IMG = [uiimage imagewithcontentsoffile: filepath2];
  6. [Image setimage: img];
  7. 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
  1. Nsfilemanager * filemanager = [nsfilemanager defaultmanager];
  2. Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
  3. // File name
  4. Nsstring * uniquepath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "pin.png"];
  5. Bool blhave = [[nsfilemanager defaultmanager] fileexistsatpath: uniquepath];
  6. If (! Blhave ){
  7. Nslog (@ "No have ");
  8. Return;
  9. } Else {
  10. Nslog (@ "have ");
  11. Bool bldele = [filemanager removeitematpath: uniquepath error: Nil];
  12. If (bldele ){
  13. Nslog (@ "DELE success ");
  14. } Else {
  15. Nslog (@ "DELE fail ");
  16. }
  17. }
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.