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