使用UIImagePickerController图像的fopen在iOS上返回NULL

时间:2014-10-13 04:11:00

标签: c++ ios objective-c

我目前在IOS应用程序中使用c ++库。它的主要功能是通过TCP / IP传输文件。 现在我已经达到了可以发送/接收纯String数据的程度,但是不能添加来自imagePicker的图像。我的fopen返回NULL;

    hFile = fopen(imageRef.c_str(), "r+");

我想知道Apple是否限制了从iphone获取文件的方式? 我甚至尝试将所选图像文件从图像拾取器复制到“文档”下面,如下所示:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    chosenImage = info[UIImagePickerControllerEditedImage];
    self.image.image = chosenImage;
    // Create paths to output images
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/thepic.jpg"];
    chosenImage = info[UIImagePickerControllerEditedImage];
    [UIImageJPEGRepresentation(chosenImage, 1.0) writeToFile:jpgPath atomically:YES];
    // Create file manager
    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    // Point to Document directory
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    // Write out the contents of home directory to console
    NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"thepic.jpg"];
    imageRef = [filePath cStringUsingEncoding:NSASCIIStringEncoding];


    [picker dismissViewControllerAnimated:YES completion:NULL];
}

0 个答案:

没有答案