How to get the name of the image saved on cameraRoll

I wanna know how can i get the name of the picture i toke or when i pick it with imagePicker so i can store it and use it later...
I searched all documentation and found nothing in c# if someone may pls help

Posts

  • LarryOBrienLarryOBrien USXamarin Team Xamurai
    edited October 2013

    To choose a photo from a gallery, refer to http://docs.xamarin.com/recipes/ios/media/video_and_photos/choose_a_photo_from_the_gallery

    To get all photos (or other assets), use ALAssetsLibrary.Enumerate, which will provide you an enumeration of groups (in this case, you'll get one group: "Saved Photos"). In your ALAssetsLibraryGroupEnumerationDelegate (GroupEnumerator), use ALAssetsGroup.Enumerate to get the individual ALAssets. The ALAsset.AssetUrl property sounds like the value you're looking for.

        var library = new ALAssetsLibrary();
        library.Enumerate(ALAssetsGroupType.SavedPhotos, GroupEnumerator, Console.WriteLine);
    
    ...
    
        private void GroupEnumerator(ALAssetsGroup group, ref bool shouldStop)
        {
            if(group == null)
            {
                shouldStop = true;
                return;
            }
            if(!shouldStop)
            {
                group.Enumerate(AssetEnumerator);
                shouldStop = false;
            }
        }
    
        private void AssetEnumerator(ALAsset asset, int index, ref bool shouldStop)
        {
            if(asset == null)
            {
                shouldStop = true;
                return;
            }
            if(!shouldStop)
            {
                Console.WriteLine(String.Format("Item[{0}] : {1}", index, asset.ToString()));
                shouldStop = false;
            }
        }
    
  • HiltonMenezesHiltonMenezes BRMember ✭✭

    Really thanks for helping me so i tried it but im getting a "cannot cast from source to destination type"

    library.Enumerate(ALAssetsGroupType.SavedPhotos, GroupEnumerator, Console.WriteLine);

    this isnt working here...

    I ll explain the better what i need with my lame english..

    I already did the imagePicker stuff so im choosing an image and putting in into an imageView but i dont know a value for me to record or how to do that when i chose the picture for my imageView...

    And after saving it i need to know what to do with it so i can "use"it again in other imageViews i already read the code but i just cant get what to do...

  • SheepssjSheepssj BRMember

    Same problem here "cannot cast from source to destination type"

  • LarryOBrienLarryOBrien USXamarin Team Xamurai
    edited October 2013

    Hmm... I just double-checked the code and cannot replicate your "Cannot cast" problem. Are you sure that you use ref bool in GroupEnumerator? That's easy to overlook.

    BUT on the specific question of "What value to record?": you'll have the NSUrl of the image from

     NSUrl referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;
    

    You can use that or just it's Path property.

  • SheepssjSheepssj BRMember

    Hey man sorry bothering you, you helped me understand a lot with your answer...

    So i got my imageView with a library image in it and i tried

    wine.Image.Info
    wine.Image.Path 
    wine.Info 
    wine.Path
    

    My doubt is

    NSUrl referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;

    If u have this image using a Library image how can i get its NSUrl? like

    NSUrl referenceURL = myImge.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;

    But i dont know how x(

  • LarryOBrienLarryOBrien USXamarin Team Xamurai

    I think you're asking "How do I get the NSUrl for an arbitrary UIImage?" The answer is that you don't: not every UIImage is associated with a URL. A UIImage might originate from a URL but it might come from being captured by the camera or being drawn by the program.

    But for the application user to select an image, you must have gotten the image in the first place, so at that point you'd presumably know its URL and you could store that data for later use when the user picks it from the table or collection view or what-have-you.

  • Marco_SeraphinMarco_Seraphin DEUniversity ✭✭

    Hi Larry, hi all,

    I used your code from october 2013 to enumerate thru the SavedPhots in the camera roll.
    What property or code do I have to use to load the photo in to an image control ?

    I tried asset.AssetUrl but it seems to be wrong.

    When I compare it with the path and file name I am getting using a MediaPicker sample it is quite different.

    Best

    Marco

Sign In or Register to comment.