Iphone document Image Storage and reading,

Source: Internet
Author: User

Iphone document Image Storage and reading,

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 ");}}



    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.