Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Why would CGImageSource.FromUrl return null?

$
0
0

Hi all,

I have a piece of code that essentially is designed to load an image from gallery and retrieve the metadata from said image. I have followed the instructions in the recipe guide Access Image Metadata, but when I get to imageSource = CGImageSource.FromUrl(url, null); it always returns null.

The full code I am using to read the metadata is below, where photoPath is a string variable containing something like {assets-library://asset/asset.JPG?id=[letters-and-numbers]&ext=JPG}:

UIImage iosImage = null;
var assetLib = new AssetsLibrary.ALAssetsLibrary();
NSUrl newImage = new NSUrl(photoPath);
assetLib.AssetForUrl(newImage, delegate (AssetsLibrary.ALAsset asset)
{
    try
    {
        // UIImage strips the metadata
        iosImage = new UIImage(asset.DefaultRepresentation.GetFullScreenImage());
    }
    catch
    {
        return;
    }

    var fileNameUrl = new NSUrl(asset.DefaultRepresentation.Filename, false); // not null
    CGImageSource myImageSource;
    // myImageSource = CGImageSource.FromUrl(fileNameUrl, null); // returns null, always!
    myImageSource = CGImageSource.FromUrl(asset.AssetUrl, null); // returns null, always!
    var ns = new NSDictionary();
    var imageProperties = myImageSource.CopyProperties(ns, 0);
    var width = imageProperties[CGImageProperties.PixelWidth];
    var height = imageProperties[CGImageProperties.PixelHeight];
    Console.WriteLine("Dimensions: {0}x{1}", width, height);
});

I have tried creating the URL from both the physical filename and the asset URL, but both return null. Neither the filename or the asset URL are null themselves (checked in debug).

Why am I getting null? Is this a bug with CGImageSource or am I doing something wrong?

Thanks


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>