private static void AddTitleToChartImage(SKBitmap chartImage, LastAlbum album) { var textColor = chartImage.GetTextColor(); var rectangleColor = textColor == SKColors.Black ? SKColors.White : SKColors.Black; var typeface = SKTypeface.FromFile(FMBotUtil.GlobalVars.FontFolder + "arial-unicode-ms.ttf"); using var textPaint = new SKPaint { TextSize = 11, IsAntialias = true, TextAlign = SKTextAlign.Center, Color = textColor, Typeface = typeface }; if (textPaint.MeasureText(album.Name) > chartImage.Width || textPaint.MeasureText(album.ArtistName) > chartImage.Width) { textPaint.TextSize = 9; } using var rectanglePaint = new SKPaint { TextAlign = SKTextAlign.Center, Color = rectangleColor.WithAlpha(140), IsAntialias = true, }; var artistBounds = new SKRect(); var albumBounds = new SKRect(); using var bitmapCanvas = new SKCanvas(chartImage); textPaint.MeasureText(album.ArtistName, ref artistBounds); textPaint.MeasureText(album.Name, ref albumBounds); var rectangleLeft = (chartImage.Width - Math.Max(albumBounds.Width, artistBounds.Width)) / 2 - 3; var rectangleRight = (chartImage.Width + Math.Max(albumBounds.Width, artistBounds.Width)) / 2 + 3; var rectangleTop = chartImage.Height - 28; var rectangleBottom = chartImage.Height - 1; var backgroundRectangle = new SKRect(rectangleLeft, rectangleTop, rectangleRight, rectangleBottom); bitmapCanvas.DrawRoundRect(backgroundRectangle, 4, 4, rectanglePaint); bitmapCanvas.DrawText(album.ArtistName, (float)chartImage.Width / 2, -artistBounds.Top + chartImage.Height - 24, textPaint); bitmapCanvas.DrawText(album.Name, (float)chartImage.Width / 2, -albumBounds.Top + chartImage.Height - 12, textPaint); }
private static void AddClassicTitleToChartImage(SKBitmap chartImage, LastAlbum album) { var textColor = chartImage.GetTextColor(); using var textPaint = new SKPaint { TextSize = 11, IsAntialias = true, Color = textColor, Typeface = SKTypeface.FromFamilyName("Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright) }; var artistBounds = new SKRect(); var albumBounds = new SKRect(); using var bitmapCanvas = new SKCanvas(chartImage); textPaint.MeasureText(album.ArtistName, ref artistBounds); textPaint.MeasureText(album.Name, ref albumBounds); bitmapCanvas.DrawText(album.ArtistName, 4, 12, textPaint); bitmapCanvas.DrawText(album.Name, 4, 22, textPaint); }