getting datetime from an image selected from the gallery

i am getting picture from the gallery and showing it in my app. what i need to do is get the datetime from it so i can save it on my web server with a new name using that datetime.

my code so far is
else if(_type.Equals("Gallery"))
{
_imagePicker = new UIImagePickerController();

            _imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
            _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary);

            _imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
            _imagePicker.Canceled += Handle_Canceled;

            NavigationController.PresentModalViewController(_imagePicker, true);
            _type = "insert";
        }

    private void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
    {
        //throw new NotImplementedException();
        bool isImage = false;
        switch (e.Info[UIImagePickerController.MediaType].ToString())
        {
            case "public.image":
                Console.WriteLine("Image selected");
                isImage = true;
                break;
            case "public.video":
                Console.WriteLine("Video selected");
                break;
        }

        // get common info (shared between images and video)
        NSUrl referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;
        if (referenceURL != null)
            Console.WriteLine("Url:" + referenceURL.ToString());

        // if it was an image, get the other image info
        if (isImage)
        {
            // get the original image
            UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;
            if (originalImage != null)
            {
                // do something with the image
                UIImage image = ResizeImage(originalImage);
                SetViewSize(image);
                imgFood.Image = image;// display
            }

            UIImage editedImage = e.Info[UIImagePickerController.EditedImage] as UIImage;
            if (editedImage != null)
            {
                // do something with the image
                Console.WriteLine("got the edited image");
                UIImage image = ResizeImage(originalImage);
                SetViewSize(image);
                imgFood.Image = editedImage;
            }

            //string dt = originalImage.GetDictionaryOfValuesFromKeys.GetImageDate
            //_meal.DateStr = dt;
        }

        // dismiss the picker
        _imagePicker.DismissModalViewController(true);
    }

i have seen some objective c code but am having difficulties translated it to C# as some of the commands are different.
like UIImagePickerControllerReferenceURL
i've tried UIImagePickerController.ReferenceURL but that doesnt help either.

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    __block NSMutableDictionary *imageMetadata = nil;
    [library assetForURL:assetURL
    resultBlock:^(ALAsset *asset) {
    NSDictionary *metadata = asset.defaultRepresentation.metadata;
    imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:metadata];
    NSLog(@%@",imageMetadata.description);
    }
    failureBlock:^(NSError *error) {
    }];
    }

any help is appreciated

Sign In or Register to comment.