using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using ServiceStack.Service; using ServiceStack.ServiceHost; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; namespace MediaBrowser.Api.Images { /// /// Class ImageWriter /// public class ImageWriter : IStreamWriter, IHasOptions { /// /// Gets or sets the request. /// /// The request. public ImageRequest Request { get; set; } /// /// Gets or sets the item. /// /// The item. public BaseItem Item { get; set; } /// /// Gets or sets a value indicating whether [crop white space]. /// /// true if [crop white space]; otherwise, false. public bool CropWhiteSpace { get; set; } /// /// The original image date modified /// public DateTime OriginalImageDateModified; /// /// The _options /// private readonly IDictionary _options = new Dictionary(); /// /// Gets the options. /// /// The options. public IDictionary Options { get { return _options; } } /// /// Writes to. /// /// The response stream. public void WriteTo(Stream responseStream) { var task = WriteToAsync(responseStream); Task.WaitAll(task); } /// /// Writes to async. /// /// The response stream. /// Task. private Task WriteToAsync(Stream responseStream) { return Kernel.Instance.ImageManager.ProcessImage(Item, Request.Type, Request.Index ?? 0, CropWhiteSpace, OriginalImageDateModified, responseStream, Request.Width, Request.Height, Request.MaxWidth, Request.MaxHeight, Request.Quality); } } }