Hi,
We are trying to initialize a PictureMarkerSymbol from an image byte array and it doesn't work.
Any help will be very appreciate.
Thanks,
Solved! Go to Solution.
You can initialize a `PictureMarkerSymbol` from a byte array of image data like this:
var pms = new PictureMarkerSymbol(); var data = File.ReadAllBytes(@"d:\images\redbeacon.png"); using (var ms = new MemoryStream(data)) { await pms.SetSourceAsync(ms); }
Does this help? Can you give a little more information about what fails for you - or share some code?
You can initialize a `PictureMarkerSymbol` from a byte array of image data like this:
var pms = new PictureMarkerSymbol(); var data = File.ReadAllBytes(@"d:\images\redbeacon.png"); using (var ms = new MemoryStream(data)) { await pms.SetSourceAsync(ms); }
Does this help? Can you give a little more information about what fails for you - or share some code?
Thanks Greg for your help.
It works this way.
FYI you can also do it with the file path:
await pms.SetSourceAsync(new Uri("file://d/images/redbeacon.png");
The benefit of that, is that the byte data is not loaded until it actually needs to be rendered (which may be never) and will be done off-thread.
Hi Morten,
Thanks for this usefull information.
It will be great if it works for embedded resource images too.
I mean using an uri like following:
pack://application:,,,/[AssemblyName];Component/[EmbeddedResourImagePath]
Hi,
You can do something like:
PictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbol(); await pictureMarkerSymbol.SetSourceAsync(new Uri("pack://application:,,,/Images/BlueStickPin.png", UriKind.Absolute)); SimpleRenderer simpleRenderer = new SimpleRenderer() { Symbol = pictureMarkerSymbol, }; GraphicsOverlay graphicsOverlay = new GraphicsOverlay() { Renderer = simpleRenderer, }; Graphic graphic = new Graphic() { Geometry = new MapPoint(0,0,SpatialReference.Create(3857)), }; graphicsOverlay.Graphics.Add(graphic); MyMapView.GraphicsOverlays.Add(graphicsOverlay);
In this case the png file properties are Resource / Do not copy.
Cheers
Mike
pack uris are indeed also supported. Is this not working for you?
I gave it a try and it works.
Maybe additional comment on SetSourceAsync method should help.