Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch: Getting an Image out of ALAssetsLibrary.AssetForUrl

In MonoTouch:

I am putting in an image from the Camera into the PhotoAlbum:

ALAssetsLibrary library = new ALAssetsLibrary();
library.WriteImageToSavedPhotosAlbum(photo.CGImage, meta, (assetUrl, error) => {
    library.AssetForUrl(assetUrl, GotAsset, FailedGotAsset);
});

The Photo is all there, works well.

On the delegate GotAsset I am attempting to get out the image, but only the Thumbnail is there. Where is the image?

    void GotAsset(ALAsset asset)
    {
         //asset has only thumbnail info???
    }

Here's what the asset looks like:

enter image description here

like image 352
Ian Vink Avatar asked Sep 11 '12 01:09

Ian Vink


2 Answers

You're not seeing, at runtime, every properties on devices because, by default, the (managed) linker is enabled (Link SDK). This will remove any code, including properties, your application is not using (and saves tons of KB and deployment times).

You can try to debug this on the simulator (which default to Don't link) by adding your own assets (in the simulator). Another way is to, temporarily, disable the linker on your device builds.

In either cases your ALAsset should be showing all documented properties.

like image 64
poupou Avatar answered Oct 12 '22 19:10

poupou


Based on @Poupou's help here's the code I added to make it work:

    void GotAsset(ALAsset asset)
    {
        ALAssetRepresentation rep = asset.DefaultRepresentation;
        var iref = rep.GetImage();
        if(iref!=null)
            DoStuffWithUIImage(UIImage.FromImage(iref));
    }
like image 23
Ian Vink Avatar answered Oct 12 '22 21:10

Ian Vink