using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using ServiceStack.Service;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Images
{
///
/// Class ImageWriter
///
public class ImageWriter : IStreamWriter
{
///
/// 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;
///
/// 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);
}
}
}