From 55d688387ee976f35e620144131c118efc1598ef Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 8 Oct 2017 16:55:29 +1100 Subject: [PATCH] Correctly handle negative x location. Fix #252 --- src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index a88a0a6d0d..47763c0aaf 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -72,10 +72,11 @@ namespace SixLabors.ImageSharp.Drawing.Processors } // Align start/end positions. - Rectangle bounds = this.Image.Bounds(); + Rectangle bounds = targetImage.Bounds(); int minX = Math.Max(this.Location.X, sourceRectangle.X); int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); maxX = Math.Min(this.Location.X + this.Size.Width, maxX); + int targetX = minX - this.Location.X; int minY = Math.Max(this.Location.Y, sourceRectangle.Y); int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom); @@ -97,7 +98,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors y => { Span background = source.GetPixelRowSpan(y).Slice(minX, width); - Span foreground = targetImage.GetPixelRowSpan(y - this.Location.Y).Slice(0, width); + Span foreground = targetImage.GetPixelRowSpan(y - this.Location.Y).Slice(targetX, width); this.blender.Blend(background, background, foreground, amount); }); }