English 中文(简体)
在应用中拍摄照片
原标题:Take Photos Within Application Saving

我正试图在我的申请范围内拍照,并让他们走一条有两个日期的道路(具体指明带照片的时间)。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image;
    image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //save to photo album
    NSString *pathString = [NSString stringWithFormat:@"Photos/%@/%@.png",timeStarted,[NSDate date]]; //create path
    NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:pathString];
    //write the files!
    [UIImagePNGRepresentation(image) writeToFile:savePath atomically:YES];
}

当我检查文件夹@"Photos/%@”时,它就显示空洞。 我做了什么错误?

www.un.org/Depts/DGACM/index_spanish.htm

这里是我的新的试验守则:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //Create the image and save it to the photo album
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

    //Create the directory and add the file name to it
    NSString *fileName = @"Test.png";
    NSString *directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Photos"];
    NSString *fullPath = [directory stringByAppendingPathComponent:fileName];
    NSLog(@"Full path: %@", fullPath);

    //Save "image" to the file path
    [UIImagePNGRepresentation(image) writeToFile:fullPath atomically:YES];

    //START CHECKING : Log to check if anything was saved
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSLog(@"Photos directory: %@", [fileMgr contentsOfDirectoryAtPath:directory error:&error]);
    //END CHECKING

    [camera dismissModalViewControllerAnimated:YES];
}

And my NSLog reads:

[640:707] Full path: /var/mobile/Applications/3EEDBD68-5496-458D-9EF0-062746847C83/Photos/Test.png
[640:707] Photos directory: (null)
最佳回答

Your pathString contains an invalid path. If you NSLog your path string it will look something like this

Photos/2011-11-16 20:16:16 +0000/2011-11-16 20:16:16 +0000.png

采用<条码>png等固定途径加以节约。 如果这项工作能够表明,这是一条道路上的问题。 在使用<代码>NSDateFormatter进行这项试验之后,该日期将作为一条有效的途径。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签