473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Clip a Graphics region

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
Jun 10 '07 #1
3 1790
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

Jun 10 '07 #2
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();

Jun 10 '07 #3
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();
Jun 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: black tractor | last post by:
HI there.. l was just wondering, if l place a "table" in the "editable region" of my template, will the text, graphics placed inside the this "table" MOVE BY ITSELF?? l mean, recently l had a...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
3
by: Martin | last post by:
I'm trying to paint my own caption bar/title bar and also my own frame border, but I'm having problems with modifying the clip region so windows doesn't paint over my stuff when I call base.WndProc...
2
by: Julie | last post by:
How do you retrieve the visible clipping region for a control? I have a control where I do some on-screen drawing (specifically ControlPaint.DrawReversibleLine()), however I need to clip the line...
3
by: BradBrigade | last post by:
Hi, I created a control deriving from System.Windows.Forms.Control. In my own OnPaint method, I can draw and set the clipping and everything is perfect. But I also added some checkboxes by...
6
by: queisser | last post by:
Hi all, I'm writing a C# app that uses copy/paste to put graphics in a window. My copy/paste logic first looks for Metafile, then for bitmap. Here's the problem: when I copy and paste a WMF...
2
by: Peter Oliphant | last post by:
I now have graphics being drawn in the Paint event of my form (yeah, and it's very cool). Problem was that it only updated any changes to these graphics when Paint was called. So, I then made it...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
0
by: dongarbage | last post by:
Hi there, I have a panel that I'm trying to draw lines on based on mouse events. I'm using a Graphics object to do this. However, the region that the graphics object will draw lines in is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.