C# images cropping,splitting,saving
Posted
by cheesebunz
on Stack Overflow
See other posts from Stack Overflow
or by cheesebunz
Published on 2010-05-24T05:06:15Z
Indexed on
2010/05/24
5:10 UTC
Read the original article
Hit count: 323
Hi, as stated in subject, i have an image:
private Image testing;
testing = new Bitmap(@"sampleimg.jpg");
I would like to split it into 3 x 3 matrix meaning 9 images in total and save it.Any tips or tricks to do this simple? I'm using visual studios 2008 and working on smart devices. Tried some ways but i can't get it. This is what i tried:
int x = 0;
int y = 0;
int width = 3;
int height = 3;
int count = testing.Width / width;
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
for (int i = 0; i < count; i++)
{
g.Clear(Color.Transparent);
g.DrawImage(testing, new Rectangle(0, 0, width, height), new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
bmp.Save(Path.ChangeExtension(@"C\AndrewPictures\", String.Format(".{0}.bmp",i)));
x += width;
}
© Stack Overflow or respective owner