Example #1
0
        private static void CheckImageRendering(ImageInputRenderer inputRenderer, int imgWidth, int imgHeight, int boxWidth, int boxHeight)
        {
            const int margin = 20;

            using (var canvas = new Image <Rgba32>(boxWidth + 2 * margin, boxHeight + 2 * margin))
            {
                var renderArea = new Rectangle(margin, margin, boxWidth, boxHeight);
                canvas.Mutate(ctx =>
                {
                    ctx.Fill(Rgba32.AliceBlue);
                    using (var img = GenerateImage(imgWidth, imgHeight))
                    {
                        inputRenderer.Render(ctx, renderArea, img);
                    }
                });
                for (var y = 0; y < canvas.Height; y++)
                {
                    for (var x = 0; x < margin; x++)
                    {
                        Assert.True(canvas[x, y] == Rgba32.AliceBlue, $"Image was rendered outside the drawing canvas at ({x}, {y})");
                    }
                    if (y < margin || y >= canvas.Height - margin)
                    {
                        for (var x = margin; x < canvas.Width - margin; x++)
                        {
                            Assert.True(canvas[x, y] == Rgba32.AliceBlue, $"Image was rendered outside the drawing canvas at ({x}, {y})");
                        }
                    }
                    for (var x = canvas.Width - margin; x < canvas.Width; x++)
                    {
                        Assert.True(canvas[x, y] == Rgba32.AliceBlue, $"Image was rendered outside the drawing canvas at ({x}, {y})");
                    }
                }
            }
        }
Example #2
0
        public void ImageRenderingWithinBoundariesTiling(int imgWidth, int imgHeight, int boxWidth, int boxHeight)
        {
            var renderer = new ImageInputRenderer(ImageScalingMode.Tile, new GraphicsOptions
            {
                Antialias = true,
                AntialiasSubpixelDepth = 8
            });

            CheckImageRendering(renderer, imgWidth, imgHeight, boxWidth, boxHeight);
        }