We have an iOS app using the 100.2.1 sdk.
We need to load an image from the MainBundle or file system to dynamically change the image to load depending on the user.
We are attempting with this code:
var url = NSBundle.MainBundle.PathForResource("StreetsIconSmall", "png", "Images");
if (url == null || url.Length == 0)
return null;
if (!System.IO.File.Exists(url))
return null;
return new Esri.ArcGISRuntime.Symbology.PictureMarkerSymbol(new Uri(url));
The file exists and it was compiled with buildaction "BundleResource"
This same code works just fine, if we put the same image on our server and use a web url such as http://domain/images/StreetsIconSmall.png.
Also, the image works when loaded to a UIImageView.
Any ideas?ArcGIS Runtime SDK for .NET@
Solved! Go to Solution.
That simply throws an invalid url exception.
Currently we found a work-around but it seems really odd that local files are not supported. Our goal is to be able to have the images in the local file system and dynamically load them.
This code below works:
UIImage img = UIImage.FromFile(url);
// url is a local file or bundle file path.
byte[] myByteArray = null;
using (NSData imageData = img.AsPNG())
{
myByteArray = new byte[imageData.Length];
Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
}
var pictureMarker = new PictureMarkerSymbol(new RuntimeImage(myByteArray));
Does a simple relative path work for you?
new Esri.ArcGISRuntime.Symbology.PictureMarkerSymbol(new Uri(("Images/StreetsIconSmall.png"));
That simply throws an invalid url exception.
Currently we found a work-around but it seems really odd that local files are not supported. Our goal is to be able to have the images in the local file system and dynamically load them.
This code below works:
UIImage img = UIImage.FromFile(url);
// url is a local file or bundle file path.
byte[] myByteArray = null;
using (NSData imageData = img.AsPNG())
{
myByteArray = new byte[imageData.Length];
Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
}
var pictureMarker = new PictureMarkerSymbol(new RuntimeImage(myByteArray));
Oops I forgot the relative parameter:
new Uri("Images/StreetsIconSmall.png", UriKind.Relative);
We did try that and although that doesn't throw the exception. It just doesn't show up on the map.
Were you able to see that there is no way to reference a local image on the device to show on a graphic? The only way we found was with the code above, but it is not as elegant as providing a local path url.
Would be nice to have that in an update.