Iphone document Image Storage and reading,

Source: Internet
Author: User

Iphone document Image Storage and reading,
Save: 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. }
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 );
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. }
 


Related Article

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.