Posts

How to crop image to circle in C#

Image
How to crop image to circle Programming Language: C#.Net IDE: Visual Studio 2015 Source code:   Source code Step 1: Open Visual Studio 2015. You have to create new project and choose Windows Forms Application. Step 2: Create a user interface by adding two(2) picture boxes and 3 buttons. Step 3: The next step is to add a class, then write in a code the codes below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 using System ; using System.Drawing ; using System.Drawing.Drawing2D ; using System.Drawing.Imaging ; public class ImageHelper { public Image CropImage (Image img) { int x = img.Width/ 2 ; int y = img.Height/ 2 ; int r = Math.Min(x, y); Bitmap tmp = null ; tmp = new Bitmap( 2 * r, 2 * r); using (Graphics g = Graphics.FromImage(tmp)) { g.SmoothingMode = SmoothingMode.AntiAlias;