Concatenating images
<p>I am trying to create an image composed of two or more images. Basically I have a list of URLs 
 and I need to use these URLs to generate an image (using the images the URLs lead to) I have tried using : <a href="http://www.switchonthecode.com/tutorials/combining-images-with-csharp" rel="nofollow">Combining Images with C#</a>. However I can't seem to get it working. the error I get is that the parameters are invalid?</p>

<p>Edit:</p>

<p>Here is the code that I am using at the moment, files, is an array of filepaths in string format.</p>

<pre><code>public static System.Drawing.Bitmap Combine(string[] files)
{
  //read all images into memory
  List&lt;System.Drawing.Bitmap&gt; images = new List&lt;System.Drawing.Bitmap&gt;();
  System.Drawing.Bitmap finalImage = null;

 try
  {
    int width = 0;
    int height = 0;

    foreach (string image in files)
    {
      //create a Bitmap from the file and add it to the list
      System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
      //FUNCTION FAILUURE HERE

      //update the size of the final bitmap
      width += bitmap.Width;
      height = bitmap.Height &gt; height ? bitmap.Height : height;

      images.Add(bitmap);
   }

    //create a bitmap to hold the combined image
    finalImage = new System.Drawing.Bitmap(width, height);

    //get a graphics object from the image so we can draw on it
    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
     {
      //set background color
      g.Clear(System.Drawing.Color.Black);

      //go through each image and draw it on the final image
      int offset = 0;
      foreach (System.Drawing.Bitmap image in images)
      {
        g.DrawImage(image, 
          new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
        offset += image.Width;
      }
    }

    return finalImage;
  }
  catch(Exception ex)
  {
    if (finalImage != null)
     finalImage.Dispose();

    throw ex;
  }
  finally
  {
     //clean up memory
    foreach (System.Drawing.Bitmap image in images)
    {
      image.Dispose();
    }
  }
}
</code></pre>

<p>I am using this function to create the bitmap image, then I am saving this bitmap image and then using a url to display the bitmap image. However the function fails to create the image at the point mark in the code (Mark by : //FUNCTION FAILURE HERE)</p>

<p>Error message : </p>

<blockquote>
  <p>Server Error in '/' Application.</p>
  
  <p>Parameter is not valid.</p>
  
  <p>Description: An unhandled exception occurred during the execution of
  the current web request. Please review the stack trace for more
  information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.ArgumentException: Parameter is not valid.</p>
  
  <p>Source Error: </p>
  
  <p>Line 75:                     finalImage.Dispose(); Line 76:  Line 77: 
  throw ex; Line 78:             } Line 79:             finally</p>
  
  <p>Source File: C:\Documents and Settings\sc541856\My Documents\Visual
  Studio 2010\Projects\Pontoon\Pontoon\Interaction.aspx.cs    Line: 77 </p>
  
  <p>Stack Trace: </p>
  
  <p>[ArgumentException: Parameter is not valid.]<br>
  Pontoon.Interfaction.Combine(String[] files) in C:\Documents and
  Settings\sc541856\My Documents\Visual Studio
  2010\Projects\Pontoon\Pontoon\Interaction.aspx.cs:77<br>
  Pontoon.Interfaction.Page_Load(Object sender, EventArgs e) in
  C:\Documents and Settings\sc541856\My Documents\Visual Studio
  2010\Projects\Pontoon\Pontoon\Interaction.aspx.cs:24<br>
  System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
  o, Object t, EventArgs e) +14<br>
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
  EventArgs e) +35    System.Web.UI.Control.OnLoad(EventArgs e) +91<br>
  System.Web.UI.Control.LoadRecursive() +74<br>
  System.Web.UI.Page.ProcessRequestMain(Boolean
  includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  +2207</p>
</blockquote>
