2015-10-14 80 views
0

我目前從事圖像處理應用程序。我有'Main'PictureBox作爲畫布。我想插入一些PictureBox到'Main'PictureBox併合併爲一個Image然後將其保存爲PNG。這是我的代碼。任何人都可以幫助我完成這項任務嗎?合併多個圖片框圖像並保存

 Bitmap bmp = new Bitmap(pictureEdit.Width, pictureEdit.Height); 
     bmp = (Bitmap)pictureEdit.Image; 

     foreach (Control c in pictureEdit.Controls) 
     { 
      if (c is Functions.pictureEdit) 
      { 
       using (var bitmap = new Bitmap(pictureEdit.Image.Width, pictureEdit.Image.Height)) { 
        using (var canvas = Graphics.FromImage(bitmap)) { 
         canvas.DrawImage(bmp, new Rectangle(0, 0, pictureEdit.Image.Width, pictureEdit.Image.Height)); 
         canvas.DrawImage(((Functions.pictureEdit)c).img, new Rectangle(0, 0, pictureEdit.Image.Width, pictureEdit.Image.Height)); 
         canvas.Save(); 
        } 
        bitmap.Save(@"D:\Test\new.png", System.Drawing.Imaging.ImageFormat.Png); 
       } 
      } 
     } 

回答

0

希望你沒關係與圖像結合在一起 下面的代碼確實是

私人位圖CombineBitmap(名單lstImages,詮釋寬度,高度INT)

{

 int iTilesPerWidth = 5; 
     //create a bitmap to hold the combined image 
     Bitmap 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)) 
     { 
      PointF point1 = new PointF(0, 0); 
      int nCount = 1; 
      foreach (Bitmap BM in lstImages) 
      { 
       //512, 256 
       g.DrawImage(BM, point1); 
       point1.X += BM.Width; 
       if (nCount % iTilesPerWidth == 0) 
       { 
        point1.X = 0; 
        point1.Y += BM.Height; 
       } 
       nCount++; 
      } 

     } 
     return finalImage; 
    }