public override ImageSource Render(Vehicle o, Size size, bool portrait) { var img = portrait ? Pictures.GetCachedImageSource(o.PortraitPaths) : Pictures.GetCachedImageSource(o.IconPaths); if (img != null) { return(img.Resize(size)); } else { // generic gray triangle if image can't be found var dv = new DrawingVisual(); var dc = dv.RenderOpen(); var geometry = new StreamGeometry(); var ctx = geometry.Open(); ctx.BeginFigure(new Point(size.Width / 2d, 0), true, true); ctx.LineTo(new Point(size.Width, size.Height), true, true); ctx.LineTo(new Point(0, size.Height), true, true); ctx.Close(); dc.DrawGeometry(new SolidColorBrush(o.Owner.Color.ToWpfColor()), null, geometry); dc.Close(); var bmp = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Default); bmp.Render(dv); return(bmp); } }
public override ImageSource Render(StellarObject o, Size size, bool portrait) { var img = portrait ? Pictures.GetCachedImageSource(o.PortraitPaths) : Pictures.GetCachedImageSource(o.IconPaths); if (img != null) { return(img.Resize(size)); } else { // generic gray rectangle if image can't be found var dv = new DrawingVisual(); var dc = dv.RenderOpen(); dc.DrawRectangle(Brushes.Gray, new Pen(Brushes.Gray, 1), new Rect(size)); dc.Close(); var bmp = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Default); bmp.Render(dv); return(bmp); } }