Click here to Skip to main content
15,883,997 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I used the below code for split an image into 16 pieces.But its not working..Please help me...
Download Picture and results here...

https://drive.google.com/file/d/0B_1aiVUSMOJocEIyb0dnWEZYak0/view?usp=sharing[^]
https://drive.google.com/file/d/0B_1aiVUSMOJobEVXLTFiYlRaYU0/view?usp=sharing[^]
Code is..
private void button1_Click(object sender, EventArgs e)
        {
            Image img = Image.FromFile(@"C:\Users\Manuprasad M\Downloads\kristen-stewart_416x416.jpg"); 
            Bitmap[,] bmps = new Bitmap[4, 4];
            for (int i = 0; i < 4; i++)
                for (int j = 0; j < 4; j++)
                {
                    bmps[i, j] = new Bitmap(104, 104);
                    Graphics g = Graphics.FromImage(bmps[i, j]);
                    g.DrawImage(img, new Rectangle(0, 0, 104, 104), new Rectangle(j * 104, i * 104, 104, 104), GraphicsUnit.Pixel);
                    g.Dispose();
                }
            pictureBox1.Image = bmps[0, 0];
            pictureBox2.Image = bmps[0, 1];
            pictureBox3.Image = bmps[0, 2];
            pictureBox4.Image = bmps[0, 3];
            pictureBox5.Image = bmps[1, 0];
            pictureBox6.Image = bmps[1, 1];
            pictureBox7.Image = bmps[1, 2];
            pictureBox8.Image = bmps[1, 3];
            pictureBox9.Image = bmps[2, 0];
            pictureBox10.Image = bmps[2, 1];
            pictureBox11.Image = bmps[2, 2];
            pictureBox12.Image = bmps[2, 3];
            pictureBox13.Image = bmps[3, 0];
            pictureBox14.Image = bmps[3, 1];
            pictureBox15.Image = bmps[3, 2];
            pictureBox16.Image = bmps[3, 3];
        }
Posted

1 solution

There's nothing wrong with the code shown here ! Something else is happening that shifts the area of the bitmap copied into each PictureBox right and truncates it.

Check your PictureBoxes to make sure their size is 104,104 and that 'SizeMode is set to 'Normal. Also, check to make sure that the PictureBoxes don't have their 'Anchor or 'Dock property set in such a way that they will re-size if the Form/ContainerControl they are in is re-sized at run-time.
 
Share this answer
 
Comments
Manu Prasad 12-Oct-14 10:30am    
You are right..Picturebox size is the problem.!!!!!!!!!!!
Manu Prasad 12-Oct-14 10:30am    
Thank you..!!!
BillWoodruff 12-Oct-14 11:22am    
Koy baht nahin :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900