C# 获取在Unity中使用的iOS映像的文件路径

C# 获取在Unity中使用的iOS映像的文件路径,c#,ios,objective-c,unity3d,uiimagepickercontroller,C#,Ios,Objective C,Unity3d,Uiimagepickercontroller,我需要为iOS映像获取一个文件路径,以便将其用于我正在Unity中进行的项目。 到目前为止,我有以下代码: #pragma mark - UIImagePickerControllerDelegate // This method is called when an image has been chosen from the library or taken from the camera. - (void)imagePickerController:(UIImagePickerControl

我需要为iOS映像获取一个文件路径,以便将其用于我正在Unity中进行的项目。 到目前为止,我有以下代码:

#pragma mark - UIImagePickerControllerDelegate
// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    NSLog(@"type=%@",type);
    if ([type isEqualToString:(NSString *)kUTTypeImage])
    {
        NSURL* imageURL = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
        NSString *urlString = [imageURL absoluteString];

        const char* cp = [urlString UTF8String];
        if(cp)
            strcpy(image_path, cp);
        else
        {//If the image path is unasigned give ERROR instead
            char* error = "ERROR";
            strcpy(image_path, error);
        }
    }

    [self dismissViewControllerAnimated:YES completion:NULL];

    // UnitySendMessage("GameObject", "VideoPicked", video_url_path);
    UnitySendMessage(callback_game_object_name, callback_function_name, image_path);
}
据我所知,它只对iPhone库有用, 有没有办法得到它的实际路径,或者我完全走错了路

作为旁注,Unity代码非常好,可以让Unity接收字符串等,但它不知道如何处理它

编辑:感谢Pankaj的回复,这个函数为我实现了

// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"setName.png"];

    //save image here and then use that imagePath
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:@"public.image"]){
        UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
        NSData *imageData = UIImagePNGRepresentation(editedImage);
        [imageData writeToFile:imagePath atomically:YES];
    }
    NSLog(@"imagePath=%@",imagePath);
    const char* cp = [imagePath UTF8String];
    strcpy(image_path, cp);

    [self dismissViewControllerAnimated:YES completion:NULL];

    UnitySendMessage(callback_game_object_name, callback_function_name, image_path);
}
//从库中选择图像或从相机中拍摄图像时,将调用此方法。
-(void)imagePickerController:(UIImagePickerController*)picker未使用信息完成PickingMediaWithInfo:(NSDictionary*)信息
{
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:0];
NSString*imagePath=[DocumentsDirectoryStringByAppendingPathComponent:@“setName.png”];
//在此处保存图像,然后使用该图像路径
NSString*mediaType=[info objectForKey:UIImagePickerControllerMediaType];
if([mediaType IsequalString:@“public.image”]){
UIImage*EditeImage=[info-objectForKey:UIImagePickerControllerEditedImage];
NSData*imageData=UIImagePNGRepresentation(编辑图像);
[imageData WriteFile:imagePath原子性:是];
}
NSLog(@“imagePath=%@”,imagePath);
const char*cp=[imagePath UTF8String];
strcpy(图像路径,cp);
[self-dismissViewControllerAnimated:是完成:空];
UnitySendMessage(回调\游戏\对象\名称、回调\函数\名称、图像\路径);
}

从PickerView获取图像,然后将其存储在文档目录中,然后将该路径用于Unity

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"setName.png"];

//save image here and then use that imagePath
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];
}

UnitySendMessage(callback_game_object_name, callback_function_name, imagePath);

从PickerView获取图像,然后将其存储在文档目录中,然后将该路径用于Unity

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"setName.png"];

//save image here and then use that imagePath
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];
}

UnitySendMessage(callback_game_object_name, callback_function_name, imagePath);

也许我不是专家,但我在这里看不到任何C代码。如果你从pickerView获取图像,那么你可以将该图像存储在该目录中,然后你可以使用该目录路径进行Unity工作。也许我不是专家,但我在这里看不到任何C代码。如果你从pickerView获取图像,那么你可以将该图像存储在中然后您可以使用该目录路径进行Unity工作。