2017-10-05 28 views
-1

我想在c#代碼中多切一張圖片。以下圖片是我的c#論壇,我可以選擇一個區域並剪切它。如何在c#中多次剪切一張圖片?

enter image description here我想要將多個切割在C#代碼 一個畫面欲重複這個過程 私人無效btnKes_Click(對象發件人,EventArgs的) { INT tiklanma = 0; (true) { tiklanma ++; } pictureBox2.Refresh();

  pictureBox2.Refresh(); 

      Bitmap sourceBitmap = new Bitmap(pictureBox1.Image, pictureBox1.Width, pictureBox1.Height); 
      Graphics g = pictureBox2.CreateGraphics(); 

      int x1, x2, y1, y2; 

      Int32.TryParse(txtX1.Text, out x1); 
      Int32.TryParse(txtX2.Text, out x2); 
      Int32.TryParse(txtY1.Text, out y1); 
      Int32.TryParse(txtY2.Text, out y2); 


      if ((x1 < x2 && y1 < y2)) 
      { 
       rectCropArea = new Rectangle(x1, y1, x2 - x1, y2 - y1); 
      } 
      else if (x2 < x1 && y2 > y1) 
      { 
       rectCropArea = new Rectangle(x2, y1, x1 - x2, y2 - y1); 
      } 
      else if (x2 > x1 && y2 < y1) 
      { 
       rectCropArea = new Rectangle(x1, y2, x2 - x1, y1 - y2); 
      } 
      else 
      { 
       rectCropArea = new Rectangle(x2, y2, x1 - x2, y1 - y2); 
      } 

      pictureBox1.Refresh(); // This repositions the dashed box to new location as per coordinates entered. 
      int sayac = 40; 

      for (int i = 0; i < tiklanma; i++) 
      { 

       PictureBox pcBx = new PictureBox(); 
       Size size = new Size(100, 100); 
       pcBx.Location(); 

       pcBx.Size = size; 

       g.DrawImage(sourceBitmap, new Rectangle(0, 0, rectCropArea.Width, rectCropArea.Height), rectCropArea, GraphicsUnit.Pixel); 
      } 

      sourceBitmap.Dispose(); 
     } 

我想在第二張圖片中多次選擇字段並保存字段。我怎樣才能做到這一點? enter image description here enter image description here

+1

[so]是*不*免費代碼寫作服務。預計你會嘗試**自己編寫代碼**。在[做更多研究]之後(http://meta.stackoverflow.com/questions/261592),如果你有問題,你可以**發佈你已經嘗試過**的清單,說明什麼是不工作的**並提供** [mcve] **。我建議閱讀[問]一個好問題和[完美問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要參加[旅遊]。 – Igor

回答

1

使用FlowLayoutPanel,每次你畫在主圖像上一個新段的新PictureBox控件添加到佈局面板。

最終你會想用這些圖片段做其他的事情,所以我還建議立即去一個自定義/用戶控件,其中包括一個PictureBox作爲一個部分。這將使以後更容易使用按鈕或每個圖片的上下文。

所有這些的細節超出了這類問題的範圍。我們需要看到更多的代碼才能夠在我們的答案中使用適當的上下文,並且結果不僅僅適合於簡單的格式QA格式。所以,去嘗試你能做的,然後當你遇到更具體的問題時回過頭來提出新的問題。

+0

Okey我添加了代碼 –