public virtual IDisposable Draw(DrawingContext drawingContext, Rect targetItemRect, int level)
{
//Default is to draw the image bits into the context:
//Do not dispose of the memory stream here, because System.Media.Windows uses
// retained mode rendering where the commands get batched to execute later.
MemoryStream imageStream = new MemoryStream(this.ImageData);
try
{
TransformedBitmap shrunkImage = ResizePng(imageStream, targetItemRect.Size);
//DrawingContext.DrawImage will scale an image to fill the size, so modify
// our target rect to be exactly the correct image position on the tile.
Rect targetImageRect = new Rect(targetItemRect.X, targetItemRect.Y,
shrunkImage.PixelWidth, shrunkImage.PixelHeight);
drawingContext.DrawImage(shrunkImage, targetImageRect);
return imageStream; //Return our stream so it can be disposed later.
}
catch
{
if (null != imageStream)
{
imageStream.Dispose();
}
throw;
}
}