From e76ff3bf160dc90968a5530b7477daaff67480b8 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 18 Sep 2012 17:39:42 -0400 Subject: Improved image processing --- .../Drawing/BaseImageProcessor.cs | 56 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Controller/Drawing/BaseImageProcessor.cs') diff --git a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs index a2b223a70..ebd0e22c8 100644 --- a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs @@ -1,6 +1,8 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; +using System.ComponentModel.Composition; using System.Drawing; +using System.Drawing.Drawing2D; namespace MediaBrowser.Controller.Drawing { @@ -15,19 +17,69 @@ namespace MediaBrowser.Controller.Drawing /// /// Processes the primary image for a BaseEntity (Person, Studio, User, etc) /// + /// The original Image, before re-sizing /// The bitmap holding the original image, after re-sizing /// The graphics surface on which the output is drawn /// The entity that owns the image - public abstract void ProcessImage(Bitmap bitmap, Graphics graphics, BaseEntity entity); + public abstract void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseEntity entity); /// /// Processes an image for a BaseItem /// + /// The original Image, before re-sizing /// The bitmap holding the original image, after re-sizing /// The graphics surface on which the output is drawn /// The entity that owns the image /// The image type /// The image index (currently only used with backdrops) - public abstract void ProcessImage(Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex); + public abstract void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex); + + /// + /// If true, the image output format will be forced to png, resulting in an output size that will generally run larger than jpg + /// + public virtual bool RequiresTransparency + { + get + { + return false; + } + } + } + + /// + /// This is demo-ware and should be deleted eventually + /// + //[Export(typeof(BaseImageProcessor))] + public class MyRoundedCornerImageProcessor : BaseImageProcessor + { + public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics g, BaseEntity entity) + { + var CornerRadius = 20; + + g.Clear(Color.Transparent); + + using (GraphicsPath gp = new GraphicsPath()) + { + gp.AddArc(0, 0, CornerRadius, CornerRadius, 180, 90); + gp.AddArc(0 + bitmap.Width - CornerRadius, 0, CornerRadius, CornerRadius, 270, 90); + gp.AddArc(0 + bitmap.Width - CornerRadius, 0 + bitmap.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); + gp.AddArc(0, 0 + bitmap.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); + + g.SetClip(gp); + g.DrawImage(originalImage, 0, 0, bitmap.Width, bitmap.Height); + } + } + + public override void ProcessImage(Image originalImage, Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex) + { + } + + public override bool RequiresTransparency + { + get + { + return true; + } + } } } -- cgit v1.2.3