title: Converting a fisheye image to landscape and diving it into four parts using c#
body: <p>I have an fisheye image and what I am trying to do is convert it into landscape.
  The code I have written converts it into landscape but when it comes to divding it into different parts it adds black parts to them.</p>
  
  <p>Can anyone help</p>
  
  <pre><code>using System;
  using System.Drawing;
  
  namespace fisheye_image
  {
      class Program
      {
          static void Main()
          {
              // assume the source image is square, and its width has even number of pixels
              Bitmap bm = (Bitmap)Image.FromFile(@"C:\Users\abc\Desktop\lillestromfisheye.jpg");
  
          int l = bm.Width / 2;
          int i, j;
          int x, y;
          double radius, theta;
          // calculated indices in Cartesian coordinates with trailing decimals
          double fTrueX, fTrueY;
          int iSourceWidth = (2 * l);
  
          int run = 0, lastWidth = 1;
  
  
          while (run&lt;4)
          {
              Bitmap bmDestination = new Bitmap(lastWidth*l, l);
              for (i = 0; i &lt; bmDestination.Height; ++i)
              {
                  radius = (double)(l - i);
  
                  for (j = run*l; j &lt; lastWidth*l ; ++j)
                  {
                      // theta = 2.0 * Math.PI * (double)(4.0 * l - j) / (double)(4.0 * l);
                      theta = 2.0 * Math.PI * (double)(-j) / (double)(4.0 * l);
  
                      fTrueX = radius * Math.Cos(theta);
                      fTrueY = radius * Math.Sin(theta);
  
                      // "normal" mode
                      x = (int)(Math.Round(fTrueX)) + l;
                      y = l - (int)(Math.Round(fTrueY));
                      // check bounds
                      if (x &gt;= 0 &amp;&amp; x &lt; iSourceWidth &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; iSourceWidth)
                      {
                          bmDestination.SetPixel(j, i, bm.GetPixel(x, y));
                      }
                  }
              }
              bmDestination.Save(@"C:\Users\abc\Desktop\fisheyelandscape"+run.ToString()+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
              run++;
              lastWidth++;
          }
        }
     }
  }
  </code></pre>
  
  <p>Below are the original and processed images</p>
  
  <p><img src="https://i.stack.imgur.com/7WooN.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/DkA92.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/9tImj.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/ayNW6.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/ZGKE7.jpg" alt="enter image description here"></p>