The idea is not to generate a new picture, but to convert the picture to a circular picture.
The implementation code is as follows:
Private image Cutellipse (image img, Rectangle rec, size size)
{
Bitmap Bitmap = new Bitmap (size. Width, size. Height);
using (Graphics g = graphics.fromimage (bitmap))
{
using (texturebrush br = new TextureBrush (IMG), System.Drawing.Drawing2D.WrapMode.Clamp, rec))
{
br. ScaleTransform (bitmap. Width/(float) rec. Width, Bitmap. Height/(float) rec. Height);
G.smoothingmode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
G.fillellipse (BR, New Rectangle (point.empty, size));
}
return bitmap;
}
Then the method can be called.
Image image = This.pictureBox1.Image;
Image newimage = Cutellipse (image, new Rectangle (0, 0,), new Size ();
This.pictureBox2.Image = NewImage;
So how do you implement WPF. Implementation is simpler, you don't need to write back code, you can use XAML directly.
<Grid>
<ellipse height= "width=" >
<Ellipse.Fill>
<imagebrush ImageSource = "Image/1_guwei4037.jpg" ></ImageBrush>
</Ellipse.Fill>
</Ellipse>
</grid >
————————————————————————————————————
@ Chen Chuqin in a group the problem with the method above is that the bottom and right edges of the method graph above are a straight line, not a smooth curve. Careful observation is indeed so.
The reason is that I draw the PictureBox control, itself PictureBox control border the length, just the full control, so the right and bottom are straight line (space is not enough).
So there are two solutions: you can draw directly into areas that do not occupy space (such as the rectangle specified in a form), or you will narrow the length and width of the drawing.