1

I'm trying to crop an image in windows forms (C#). I did it with straight corners. But I want to split it with curve lines.

A Single image is split into a 3x3 image and then placed in 9 different pictureBoxes. Here is my current code:

Image img = pictureBox1.Image;
int widththird = (int)((double)img.Width / 3.0 + 0.5);
int heightthird = (int)((double)img.Height / 3.0 + 0.5);
Bitmap[,] bmps = new Bitmap[3, 3];
for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < 3; j++)
    {
        bmps[i, j] = new Bitmap(widththird, heightthird);
        Graphics g = Graphics.FromImage(bmps[i,j]);
        g.DrawImage(img, new Rectangle(0, 0, widththird, heightthird), new 
        Rectangle(j * widththird, i * heightthird, widththird, heightthird), 
        GraphicsUnit.Pixel);
        g.Dispose();

    }

}
pictureBox2.Image = bmps[0, 0];
pictureBox3.Image = bmps[0, 1];
pictureBox4.Image = bmps[0, 2];
pictureBox5.Image = bmps[1, 0];
pictureBox6.Image = bmps[1, 1];
pictureBox7.Image = bmps[1, 2];
pictureBox8.Image = bmps[2, 0];
pictureBox9.Image = bmps[2, 1];
pictureBox10.Image = bmps[2, 2];

Q: How can I can crop/split the image with curves and export the pieces?


My output:

My output

I want it cropped like this:

I want it cropped like this

Dan Byström
  • 9,067
  • 5
  • 38
  • 68
  • Please provide explanation/screenshot about what is it doing now, and the actual question. Thanks – Tatranskymedved Dec 14 '17 at 07:04
  • i have uploaded the output and what i want it to be :) – Zerry Mirza Dec 14 '17 at 07:11
  • I still don't understand, based on the output it seems that You are doing the splitting of image. What is the problem? What You expect? – Tatranskymedved Dec 14 '17 at 07:13
  • if u see in the output. I have 9 picture boxes where the 9 bitmap images are placed and these picture boxes have straight border. I just want the border to be curved and crop the image accordingly. As in image "I want tit to be cropped like this". – Zerry Mirza Dec 14 '17 at 07:18
  • A bitmap will always be rectangular. But you can make parts of it transparent to make them look irregular. How do you plan to represent the curves? – Dan Byström Dec 14 '17 at 12:28
  • Can u please send me the code to make bitmaps curved and irregular. i have uploaded the image of how do I want it :) – Zerry Mirza Dec 14 '17 at 12:37
  • @DanByström please send me the code or link how to do this – Zerry Mirza Dec 14 '17 at 12:56
  • related: https://stackoverflow.com/questions/33820712/clip-an-image-in-a-specific-shape-net – Crowcoder Dec 14 '17 at 14:13

0 Answers0