/// <summary> /// Draws the indicator. /// </summary> /// <param name="wand">The wand.</param> /// <param name="imageWidth">Width of the image.</param> /// <param name="imageHeight">Height of the image.</param> /// <param name="options">The options.</param> private void DrawIndicator(MagickWand wand, int imageWidth, int imageHeight, ImageProcessingOptions options) { if (!options.AddPlayedIndicator && !options.UnplayedCount.HasValue && options.PercentPlayed.Equals(0)) { return; } try { if (options.AddPlayedIndicator) { var currentImageSize = new ImageSize(imageWidth, imageHeight); var task = new PlayedIndicatorDrawer(_appPaths, _httpClient, _fileSystem).DrawPlayedIndicator(wand, currentImageSize); Task.WaitAll(task); } else if (options.UnplayedCount.HasValue) { var currentImageSize = new ImageSize(imageWidth, imageHeight); new UnplayedCountIndicator(_appPaths, _fileSystem).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value); } if (options.PercentPlayed > 0) { new PercentPlayedDrawer().Process(wand, options.PercentPlayed); } } catch (Exception ex) { _logger.ErrorException("Error drawing indicator overlay", ex); } }
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); using (var draw = new DrawingWand()) { using (PixelWand pixel = new PixelWand()) { pixel.Color = "#52B54B"; pixel.Opacity = 0.2; draw.FillColor = pixel; draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20); pixel.Opacity = 0; pixel.Color = "white"; draw.FillColor = pixel; draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem); draw.FontStyle = FontStyleType.NormalStyle; draw.TextAlignment = TextAlignType.CenterAlign; draw.FontWeight = FontWeightType.RegularStyle; draw.TextAntialias = true; var fontSize = 30; var y = OffsetFromTopRightCorner + 11; if (text.Length == 1) { x += 1; } else if (text.Length == 2) { x += 1; } else if (text.Length >= 3) { //x += 1; y -= 2; fontSize = 24; } draw.FontSize = fontSize; draw.DrawAnnotation(x, y, text); draw.FillColor = pixel; wand.CurrentImage.DrawImage(draw); } } }