DrawImage scales original image
<p>I am stitching several images together vertically and horizontally to create one bigger image (in which the total width and height are the sum of the widths and heights of the individual images) using <code>Bitmap</code> and <code>System.Drawing.Graphics</code> in C#. The size of the individual images are 256 px by 256 px. </p>

<p><strong>When I use <code>DrawImage</code> from <code>System.Drawing.Graphics</code>, why do I get a scaled and/or zoomed in version of the original image?</strong></p>

<hr>

<p>Here is the original image:</p>

<p><a href="https://i.stack.imgur.com/IYfNz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IYfNz.png" alt="original image"></a></p>

<hr>

<p>When I retrieve the image programmatically and write to file in code, I get the following:</p>

<pre><code>var result = httpClient.GetStreamAsync(/* url */);
var bitmap = new Bitmap(await result);
...
using (var memory = new MemoryStream())
{ 
   using (var fs = new FileStream(/* path */, FileMode.OpenOrCreate, FileAccess.ReadWrite))
   {
        bitmap.Save(memory, ImageFormat.Png); // I save to .png if that makes a difference
        var bytes = memory.ToArray();
        await fs.WriteAsync(bytes, 0, bytes.Length);
   }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/ph0Y5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ph0Y5.png" alt="programmatic retrieval of image in code"></a></p>

<p>I see no difference. So far, so good. </p>

<hr>

<p>However, when I attempt to stitch images horizontally, I get the following:</p>

<p>Note: For reference, the image above is at the far-right in the stitched image below. </p>

<p><a href="https://i.stack.imgur.com/xUlfA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xUlfA.png" alt="horizontally stitched image"></a></p>

<p>It looks scaled, zoomed in, and definitely not like the original or programmatically retrieved individual image above. </p>

<hr>

<p>Here is the code I use to stitch the images together:</p>

<p>Note: If <code>byWidth</code> is <code>true</code>, I stitch images horizontally. </p>

<pre><code>private Bitmap MergeImages(IEnumerable&lt;Bitmap&gt; images, bool byWidth)
{
    var enumerable = images as IList&lt;Bitmap&gt; ?? images.ToList();

    var width = 0;
    var height = 0;

    foreach (var image in enumerable)
    {
        if (byWidth)
        {
            width += image.Width;
            height = image.Height;
        }
        else
        {
            width = image.Width;
            height += image.Height;
        }
    }

    var bitmap = new Bitmap(width, height);
    using (var g = Graphics.FromImage(bitmap))
    {
        var localWidth = 0;
        var localHeight = 0;

        foreach (var image in enumerable)
        {
            if (byWidth)
            {
                g.DrawImage(image, localWidth, 0);
                localWidth += image.Width;
            }
            else
            {
                g.DrawImage(image, 0, localHeight);
                localHeight += image.Height;
            }
        }
    }

    return bitmap;
}
</code></pre>