We are trying to initialize a PictureMarkerSymbol from an image byte array and it doesn't work.
Any help will be very appreciate.
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))
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.
Thanks for this usefull information.
It will be great if it works for embedded resource images too.
I mean using an uri like following:
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)),
In this case the png file properties are Resource / Do not copy.
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.
Retrieving data ...