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