Windows Develop Bookmark and Share   
 index > Windows Forms General > Crop a circle image from a square picture
 

Crop a circle image from a square picture

hi,
I making a windows application in C# and my problem is that,
I have a square picture. I need to draw a circle on it, and everything
outside that circle to be set to a certain color, so the image looks framed

On other words, I want to crop a circle form a rectangular picture

Any hints/any help ..........

thanks in advance
babitas  Tuesday, April 21, 2009 11:47 AM
You can do this by using a texture brush...Try this..
theImage = new Bitmap("YouImage.jpg");

      

Graphics g = GetGraphichs(); // such as e.Graphics inside a OnPaint method;

Brush tBrush = new TextureBrush(theImage, new Rectangle(0, 0,theImage.Width, theImage.Height));

g.FillEllipse(tBrush, GetTheRectangle());
tBrush.Dispose();

Doing stuff with .net
Moim Hossain  Tuesday, April 21, 2009 11:55 AM
Make this PictureBox control round:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0, 0, pictureBox1.Width, pictureBox1.Height);
pictureBox1.Region = new Region(path);
}
}

Please post these questions to Windows Forms General in the future.
Hans Passant.
nobugz  Tuesday, April 21, 2009 12:31 PM
You can do this by using a texture brush...Try this..
theImage = new Bitmap("YouImage.jpg");

      

Graphics g = GetGraphichs(); // such as e.Graphics inside a OnPaint method;

Brush tBrush = new TextureBrush(theImage, new Rectangle(0, 0,theImage.Width, theImage.Height));

g.FillEllipse(tBrush, GetTheRectangle());
tBrush.Dispose();

Doing stuff with .net
Moim Hossain  Tuesday, April 21, 2009 11:55 AM
hi,

where i can find GetGraphichs(); method ....
plz help me..
thanks
babitas  Tuesday, April 21, 2009 12:18 PM
Make this PictureBox control round:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0, 0, pictureBox1.Width, pictureBox1.Height);
pictureBox1.Region = new Region(path);
}
}

Please post these questions to Windows Forms General in the future.
Hans Passant.
nobugz  Tuesday, April 21, 2009 12:31 PM

You can use google to search for other answers

Custom Search

More Threads

• Simple code question
• Visual Windows Spy request.
• Multiple Document Form Based Applications
• PictureBox Alpha Icon problem
• Converting ASCII string to a hex
• How to change user rights in directory in NTFS
• Creating custom extended Calendar control
• Layer Seperation and Circular Dependencies
• localization and language bars
• How to set background color of dialog box using Win32 API