title: Split Image as Rows x Columns equal sized Image Matrix Using C#
body: <blockquote>
    <p>how to split an image into Equal Size <code>3x3,3x4,4x4,6x6,4x6,6x8</code> something like that</p>
  </blockquote>
  
  <p>Conceptualize by given Image: Convert simple image into that form,
  <img src="https://i.stack.imgur.com/dCCBv.png" alt="enter image description here"></p>
  
  <p>In Given Answer It is General Purpose algorithm to Split an Image into proper scaled <strong>Rows x Columns Equal sized Image Matrix</strong> It Gives out put Like</p>
  
  <pre><code>1 4 7
  2 5 8
  3 6 9
  </code></pre>
  
  <p>I Used Following Code ....But It Doesn't worked perfectally</p>
  
  <p>Load Button Code: <strong>Load The Image into Variable image1</strong></p>
  
  <pre><code>Image image1;
  private void btn_Open_File_BG_Click(object sender, EventArgs e)
  {
      OpenFileDialog openDialog = new OpenFileDialog();
      if (openDialog.ShowDialog() == DialogResult.OK)
      {
          image1 = new Bitmap(openDialog.FileName);
      }
  }
  </code></pre>
  
  <p>Process Button Code:<strong>Split Picture &amp; Save or Use</strong></p>
  
  <pre><code>private void Img_BG_process_Click(object sender, EventArgs e)
          {
              int rows = 5;//No of Rows as per Desire
              int columns = 6;//No of columns as per Desire
              var imgarray = new Image[rows, columns];//Create Image Array of Size Rows X Colums
              var img = image1;//Get Image from anywhere, From File Or Using Dialogbox used previously
              int height = img.Height;
              int width = img.Width;//Get image Height &amp; Width of Input Image
              int one_img_h = height / rows;
              int one_img_w = width / columns;//You need Rows x Columns, So get 1/rows Height, 1/columns width of original Image
              for (int i = 0; i &lt; rows; i++)
              {
                  for (int j = 0; j &lt; columns; j++)
                  {
                      imgarray[i, j] = new Bitmap(one_img_w, one_img_h);//generating new bitmap
                      var graphics = Graphics.FromImage(imgarray[i, j]);
                      graphics.DrawImage(img, new Rectangle(0, 0, one_img_w, one_img_h), new Rectangle(i * one_img_w, j * one_img_h, one_img_w, one_img_h), GraphicsUnit.Pixel);//Generating Splitted Pieces of Image
                      graphics.Dispose();
                  }
              }
  //Image Is spitted You can use it by getting image from **imgarray[Rows, Columns]**
  //Or You can Save it by using Following Code
  
  
              var destinationFolderName = "";//Define a saving path
              FolderBrowserDialog FolderBrowserDialog1 = new FolderBrowserDialog();
              DialogResult result = FolderBrowserDialog1.ShowDialog();//Get folder Path Where splitted Image Saved
              if (result == DialogResult.OK)
              {
                  destinationFolderName = FolderBrowserDialog1.SelectedPath;
                  for (int i = 0; i &lt; rows; i++)
                  {
                      for (int j = 0; j &lt; columns; j++)
                      {
                          imgarray[i, j].Save(@"" + destinationFolderName + "/Image_" + i + "_" + j + ".jpg");//Save every image in Array [row][column] on local Path
                      }
                  }
              }
          } 
  </code></pre>