On Jun 10, 3:04 pm, Manuel <vanilla...@the.skywrote:
Hi to all,
I have a System.Drawing.Graphics, I need to clip a region and put it in
a different another Graphics with the size of clipped region.
There's suggestion or a tutorial?
Thanks in advice
x1 - starting X
y1 - starting Y
newHeight, newWidth - new dimensions
Bitmap sourceBitmap1 = new Bitmap(stream);
Color col;
Bitmap sourceBitmap2 = new Bitmap(newWidth, newHeight);
for (int i = x1; i <= newWidth - 1; i++)
{
for (int j = y1; j <= newHeight - 1; j++)
{
col = sourceBitmap1.GetPixel(i, j);
sourceBitmap2.SetPixel(i - x1, j - y1, col);
}
}
Bitmap targetBitmap = new Bitmap(newWidth, newHeight);
Graphics g = Graphics.FromImage(targetBitmap);
Rectangle rect = new Rectangle(0, 0, newWidth, newHeight);
g.DrawImage(sourceBitmap2, rect);
targetBitmap.Save(filename);
g.Dispose();
targetBitmap.Dispose();