PercentPlayedDrawer.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Drawing;
  2. using System.Globalization;
  3. namespace MediaBrowser.Server.Implementations.Drawing
  4. {
  5. public class PercentPlayedDrawer
  6. {
  7. private const int IndicatorWidth = 80;
  8. private const int IndicatorHeight = 50;
  9. private const int FontSize = 30;
  10. private readonly CultureInfo _usCulture = new CultureInfo("en-US");
  11. public void Process(Graphics graphics, Size imageSize, int percent)
  12. {
  13. var x = imageSize.Width - IndicatorWidth;
  14. using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 102, 192, 16)))
  15. {
  16. graphics.FillRectangle(backdroundBrush, x, 0, IndicatorWidth, IndicatorHeight);
  17. var text = string.Format("{0}%", percent.ToString(_usCulture));
  18. x = imageSize.Width - (percent < 10 ? 66 : 75);
  19. using (var font = new Font(FontFamily.GenericSansSerif, FontSize, FontStyle.Regular, GraphicsUnit.Pixel))
  20. {
  21. using (var fontBrush = new SolidBrush(Color.White))
  22. {
  23. graphics.DrawString(text, font, fontBrush, x, 6);
  24. }
  25. }
  26. }
  27. }
  28. }
  29. }