コード例 #1
0
 private static void SaveImage(MagickImage image, int width, int height, ResizeBehaviour resizeBehaviour)
 {
     image.Write(
         Path.Combine(
             Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
             string.Format("{0}-{1}-{2}x{3}.jpeg", DateTime.UtcNow.Ticks, resizeBehaviour, width, height)));
 }
コード例 #2
0
        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);
        }
コード例 #3
0
 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();
 }
コード例 #4
0
        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));
                        }
                    }
        }
コード例 #5
0
 public Thumbnail(int width, int height, string alias, ResizeBehaviour resizeBehaviour, params Thumbnail[] children)
     : this(width, height, alias, resizeBehaviour, ProcessingBehaviour.None, children)
 {
 }