replace System.Drawing with ImageMagick

This commit is contained in:
Luke Pulverenti
2015-02-19 20:57:10 -05:00
parent d155139e28
commit 5e10e0ff19
8 changed files with 175 additions and 537 deletions
@@ -1,5 +1,5 @@
using System;
using System.Drawing;
using ImageMagickSharp;
using System;
namespace MediaBrowser.Server.Implementations.Drawing
{
@@ -7,26 +7,32 @@ namespace MediaBrowser.Server.Implementations.Drawing
{
private const int IndicatorHeight = 8;
public void Process(Graphics graphics, Size imageSize, double percent)
public void Process(MagickWand wand, double percent)
{
var y = imageSize.Height - IndicatorHeight;
var currentImage = wand.CurrentImage;
var height = currentImage.Height;
using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 0, 0, 0)))
using (var draw = new DrawingWand())
{
const int innerX = 0;
var innerY = y;
var innerWidth = imageSize.Width;
var innerHeight = imageSize.Height;
graphics.FillRectangle(backdroundBrush, innerX, innerY, innerWidth, innerHeight);
using (var foregroundBrush = new SolidBrush(Color.FromArgb(82, 181, 75)))
using (PixelWand pixel = new PixelWand())
{
double foregroundWidth = innerWidth;
var endX = currentImage.Width - 1;
var endY = height - 1;
pixel.Color = "black";
pixel.Opacity = 0.4;
draw.FillColor = pixel;
draw.DrawRectangle(0, endY - IndicatorHeight, endX, endY);
double foregroundWidth = endX;
foregroundWidth *= percent;
foregroundWidth /= 100;
graphics.FillRectangle(foregroundBrush, innerX, innerY, Convert.ToInt32(Math.Round(foregroundWidth)), innerHeight);
pixel.Color = "#52B54B";
pixel.Opacity = 0;
draw.FillColor = pixel;
draw.DrawRectangle(0, endY - IndicatorHeight, Convert.ToInt32(Math.Round(foregroundWidth)), endY);
wand.CurrentImage.DrawImage(draw);
}
}
}