You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
napdump/ndview/ThumbnailGenerator.cs

35 lines
736 B

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tools;
using System.IO;
using ImageMagick;
namespace ndview
{
public class ThumbnailGenerator
{
public readonly int Width,Height;
public ThumbnailGenerator(int width) : this(width,0){}
public ThumbnailGenerator(int width, int height)
{
(Width, Height) = (width, height);
}
public Task Thumbnail(Stream from, Stream to, CancellationToken token=default)
=> Task.Run(()=> {
using var image= new MagickImage();
image.Read(from);
token.ThrowIfCancellationRequested();
image.Resize(200, 0);
token.ThrowIfCancellationRequested();
image.Write(to);
token.ThrowIfCancellationRequested();
});
}
}