Exemplo n.º 1
0
        public void ImageShouldDrawTransformedImage <TPixel>(TestImageProvider <TPixel> provider, PixelBlenderMode mode)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
                using (var blend = Image.Load <TPixel>(TestFile.Create(TestImages.Bmp.Car).Bytes))
                {
                    Matrix3x2 rotate = Matrix3x2Extensions.CreateRotationDegrees(45F);
                    Matrix3x2 scale  = Matrix3x2Extensions.CreateScale(new SizeF(.25F, .25F));
                    Matrix3x2 matrix = rotate * scale;

                    // Lets center the matrix so we can tell whether any cut-off issues we may have belong to the drawing processor
                    Rectangle srcBounds      = blend.Bounds();
                    Rectangle destBounds     = TransformHelpers.GetTransformedBoundingRectangle(srcBounds, matrix);
                    Matrix3x2 centeredMatrix = TransformHelpers.GetCenteredTransformMatrix(srcBounds, destBounds, matrix);

                    // We pass a new rectangle here based on the dest bounds since we've offset the matrix
                    blend.Mutate(x => x.Transform(
                                     centeredMatrix,
                                     KnownResamplers.Bicubic,
                                     new Rectangle(0, 0, destBounds.Width, destBounds.Height)));

                    var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2);
                    image.Mutate(x => x.DrawImage(blend, mode, .75F, position));
                    image.DebugSave(provider, new[] { "Transformed" });
                }
        }
 /// <inheritdoc/>
 protected override Matrix3x2 GetProcessingMatrix(Rectangle sourceRectangle, Rectangle destinationRectangle)
 {
     return(TransformHelpers.GetCenteredTransformMatrix(sourceRectangle, destinationRectangle, this.TransformMatrix));
 }