private void PerformResizeTest( SampleImage sampleImage, int desiredWidth, int desiredHeight, ResizeBehaviour resizeBehaviour, ProcessingBehaviour processingBehaviour, params Action <Bitmap>[] asserts) { using (var inputStream = sampleImage.Open()) using (var input = new MagickImage(inputStream)) using (var outputStream = new MemoryStream()) { this.target.Resize(input, outputStream, desiredWidth, desiredHeight, resizeBehaviour, processingBehaviour); ////SaveImage(input, desiredWidth, desiredHeight, resizeBehaviour); outputStream.Seek(0, SeekOrigin.Begin); var outputImage = new Bitmap(outputStream); foreach (var assert in asserts) { assert(outputImage); } if (resizeBehaviour == ResizeBehaviour.MaintainAspectRatio) { Assert.IsTrue( this.AreClose( sampleImage.Width / (double)sampleImage.Height, outputImage.Width / (double)outputImage.Height)); } else { Assert.IsTrue( this.AreClose(desiredWidth / (double)desiredHeight, outputImage.Width / (double)outputImage.Height)); } } }
public Thumbnail(int width, int height, string alias, ResizeBehaviour resizeBehaviour, ProcessingBehaviour processingBehaviour, params Thumbnail[] children) { this.Width = width; this.Height = height; this.Alias = alias; this.ResizeBehaviour = resizeBehaviour; this.ProcessingBehaviour = processingBehaviour; this.Children = children == null ? new List <Thumbnail>() : children.ToList(); }
public void Resize(MagickImage input, Stream output, int width, int height, ResizeBehaviour resizeBehaviour, ProcessingBehaviour processingBehaviour) { switch (resizeBehaviour) { case ResizeBehaviour.MaintainAspectRatio: this.ResizeMaintainAspectRatio(input, output, width, height); break; case ResizeBehaviour.CropToAspectRatio: this.ResizeCropToAspectRatio(input, output, width, height); break; } if (processingBehaviour == ProcessingBehaviour.Darken) { input.Colorize(new MagickColor(0, 0, 0), new Percentage(60)); } else if (processingBehaviour == ProcessingBehaviour.Lighten) { input.Colorize(new MagickColor(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue), new Percentage(75)); input.Draw( new DrawableGravity(Gravity.Center), new DrawableFont("Arial"), new DrawableFillColor(Color.Black), new DrawablePointSize(28), new DrawableText(0, 0, "Preview")); } input.Write(output); }