- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
        UIImage *baseImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (baseImage == nil) return;
        compositeImage = [self addOverlayToBaseImage:baseImage];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
        NSDate* date = [NSDate date];
        NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
        [formatter setDateFormat:@"yyyyMMddHHMMSS"];
        NSString* str = [formatter stringFromDate:date];
        //给照片按拍摄时间命名
        NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",str]];
    BOOL result=[UIImagePNGRepresentation(compositeImage)writeToFile: uniquePath atomically:YES];
    if (result) {
        NSLog(@"success");
    }        
}

 

    NSString *DocumentsDirectory = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"XXX.db"];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    if (![fileManager fileExistsAtPath:DocumentsDirectory]) {
        NSString *newFile = [[NSBundle mainBundle] pathForResource:@"XXX.db" ofType:nil];
        [fileManager copyItemAtPath:newFile toPath:DocumentsDirectory error:nil];
    }
    [fileManager release];
posted on 2012-05-23 10:57  chivas  阅读(383)  评论(0编辑  收藏  举报