PC Review


Reply
Thread Tools Rate Thread

Clip a Graphics region

 
 
Manuel
Guest
Posts: n/a
 
      10th Jun 2007
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
 
Reply With Quote
 
 
 
 
Alex Meleta
Guest
Posts: n/a
 
      10th Jun 2007
Hi Nigel,

This article can be useful: http://www.dotnet247.com/247referenc...29/145049.aspx

Regards,
Alex
http://devkids.blogspot.com



> 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
>



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10th Jun 2007
On Jun 10, 3:04 pm, Manuel <vanilla...@the.sky> wrote:
> 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();

 
Reply With Quote
 
Manuel
Guest
Posts: n/a
 
      10th Jun 2007
Manuel ha scritto:
> 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


Thanks to all,
I have solved in this way:

System.Drawing.Image img_clipped = new Bitmap(256*2, 256);
Rectangle rec = new Rectangle(10, 10, 100, 200);
Graphics g_clipped = Graphics.FromImage(img_clipped);
/* Using rectangles */
RectangleF destRect = new Rectangle(0, 0, 200, 200);
RectangleF srcRect2 = new Rectangle(0, 0, 200, 200);
g_clipped.DrawImage(img, destRect, srcRect2, GraphicsUnit.Pixel);
g_clipped.Save();
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot go back to old clip region Reiner Obrecht Microsoft Dot NET Framework Forms 2 10th Apr 2009 10:12 PM
Clip Art combining 2 graphics into 1 Cindy B Microsoft Access 1 3rd Sep 2008 10:48 PM
how do you change the size of the clipping region of a Graphics object dongarbage@hotmail.com Microsoft C# .NET 0 24th Jan 2007 08:22 PM
How to get control clip region? Julie Microsoft C# .NET 2 16th Apr 2005 12:43 PM
Modifying clip region Martin Microsoft C# .NET 3 14th Feb 2005 01:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:57 PM.