大概意思就是不生成新的图片,而是将图片转换为圆形图片。
实现代码如下:
private Image CutEllipse(Image img, Rectangle rec, Size size)
{
Bitmap thumb = new Bitmap(size.Width, size.Height);
using (Graphics g = Graphics.FromImage(thumb))
{
using (TextureBrush br = new TextureBrush(img,System.Drawing.Drawing2D.WrapMode.Clamp, rec))
{
br.ScaleTransform(thumb.Width / (float)rec.Width, thumb.Height / (float)rec.Height);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.FillEllipse(br, new Rectangle(Point.Empty, size));
}
}
return thumb;
}
然后调用方法即可。
Image image = this.pictureBox1.Image;
Image newImage = CutEllipse(image, new Rectangle(0, 0, 150, 150), new Size(150, 150));
this.pictureBox2.Image = newImage;
那么用WPF如何实现?实现就更简单了,不需要写后台代码,直接利用XAML即可。
原文:http://blog.csdn.net/chinacsharper/article/details/50854852