PictureMarkerSymbol Source Does Not Update Properly

342
2
04-25-2013 12:19 PM
Labels (1)
AaronHigh
New Contributor III
Hello,

If I am using a PictureMarkerSymbol with a BitmapImage as the Source property in a GraphicsLayer and change the Source property the symbol does not update. However, if I set the source to some other value and then immediately set it back to the BitmapImage it works properly. See example below:

PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol();
markerSymbol.Geometry = new MapPoint(0,0);

//This method doesn't work:
private void changeSymbol()
{
    //ASSUMPTIONS: "this.bitmap" is being updated by some external class/method before the changeSymbol() method is called
    markerSymbol.Source = this.bitmap;
}

//This method does:
internal static BitmapSource dummyBitmap = BitmapSource.Create(1, 1, 8, 8, PixelFormats.Indexed1, BitmapPalettes.BlackAndWhiteTransparent, new byte[1], 1);

private void changeSymbol()
{
    //ASSUMPTIONS: "this.bitmap" is being updated by some external class/method before the changeSymbol() method is called
    markerSymbol.Source = dummyBitmap;
    markerSymbol.Source = this.bitmap;
}


This would be used in a case where the "this.bitmap" is being updated on a timer and the changeSymbol() is called after the update on the same timer tick. Am I missing something here?

Thanks.
0 Kudos
2 Replies
AaronHigh
New Contributor III
As an update to this question, I was able to find this using .NET Reflector:

private bool IsSpuriousSourcePropertyChangedEvent(DependencyPropertyChangedEventArgs e)
{
    return (this.GetImageUri(e.OldValue) == this.GetImageUri(e.NewValue));
}

private string GetImageUri(object image)
{
    if ((image is BitmapImage) || (image is BitmapFrame))
    {
        return image.ToString();
    }
    return null;
}


Which would indicate that it's only actually updating the source property if its URI has changed. Given that information, has anyone experienced an unmanaged memory leak in the Accelerated Display when using a PictureMarkerSymbol with a high update rate (source property updating in the sub-500ms range)?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

It may be worth wrapping your image/Bitmap creation with a .BeginInit() call and an .EndInit() call. However, there is also a known issue in 10.1.1 where PictureMarkerSymbols do not update if you change the Source property using a BitmapImage created from a StreamSource. The workaround is to set the Uri, or alternatively you can use RenderTargetBitmap to force an off-screen render of a Visual element and then use the RenderTargetBitmap as the Source property of the PictureMarkerSymbol. There's an example of the latter approach in the DevSummit 2013 demos on GitHub: https://github.com/Esri/tips-and-tricks-wpf/tree/master/Best-Development-Practices-and-Patterns/Pict.... That Tips and Tricks repo contains all our demos from this year's Dev Summit. You can also find them on ArcGIS.com: http://www.arcgis.com/home/item.html?id=3f69c79bbd7340b09fad396647a977a5.

Please can you post a simple reproducer for the memory leak issue you're seeing? (or email me on mbranscomb@esri.com).

Cheers

Mike
0 Kudos