2017-10-05 59 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我添加了代码 –