MonoTouch: Getting an Image out of ALAssetsLibrary

2019-06-22 13:08发布

问题:

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:

回答1:

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.



回答2:

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));
    }