title: How To split a big image into smaller A4 size pieces using DrawImage method of Graphics class
body: <p>DrawImage method of Graphics class is not creating high quality images. In this method I am splitting a master image into multiple image but the code generating first image in very low quality. But it is generating full black images for remaining height. </p>
  
  <pre><code>     public static Bitmap[] Split(byte[] ByteImage)
              {
      // MasterImage:  there is no problem in master image. it is saving it in good quality.
                  MemoryStream ms = new MemoryStream(ByteImage);
  
                  System.Drawing.Image MasterImage = System.Drawing.Image.FromStream(ms);
  
                  MasterImage.Save(HttpContext.Current.Server.MapPath("../../../App_Shared/Reports/Temp/MasterImage.Bmp"), ImageFormat.Bmp);
  
  
      //Split master image into multiple image according to height / 1000
                  Int32 ImageHeight = 1000, ImageWidth = MasterImage.Width, MasterImageHeight = MasterImage.Height;
                  int PageCount = 0;
                  Int32 TotalPages = MasterImage.Height / 1000;
                  Bitmap[] imgs = new Bitmap[TotalPages];
  
                  for (int y = 0; y + 1000 &lt; MasterImageHeight; y += 1000, PageCount++)
                  {
                      imgs[PageCount] = new Bitmap(ImageWidth, ImageHeight, PixelFormat.Format32bppPArgb);
  
                      using (Graphics gr = Graphics.FromImage(imgs[PageCount]))
                      {
                          gr.CompositingQuality = CompositingQuality.HighQuality;
                          gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                          gr.SmoothingMode = SmoothingMode.HighQuality;
  //First image now working with this code line
   gr.DrawImage(MasterImage, new System.Drawing.Rectangle(0, y, ImageWidth, ImageHeight),new System.Drawing.Rectangle(0, 0, ImageWidth, ImageHeight), GraphicsUnit.Pixel); //new System.Drawing.Rectangle(new Point(0, y), new Size(ImageWidth, ImageHeight)));
                          //gr.DrawImage(MasterImage, new System.Drawing.Rectangle(0, y, ImageWidth, ImageHeight)); //new System.Drawing.Rectangle(new Point(0, y), new Size(ImageWidth, ImageHeight)));
  
                          string FilePath = HttpContext.Current.Server.MapPath("../../../App_Shared/Reports/Temp/Image" + PageCount.ToString() + ".bmp");
                          imgs[PageCount].Save(FilePath, System.Drawing.Imaging.ImageFormat.Bmp);
      //Here it is saving images. I got first image with very poor quality but remaining in total balck color.
                          gr.Dispose();
                      }
                  }
  
                  return imgs;
              }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/v3RUi.png" alt="My First Image">
  <img src="https://i.stack.imgur.com/zDk1E.png" alt="and all the other image are black"></p>