1.算法
/// <summary>
/// 圆形截图
/// </summary>
/// <param name="rec">截取部分矩形的值:rec(X,Y, Width,Height)</param>
/// <param name="size">画布大小size(宽,高)</param>
/// <returns></returns>
public static BitmapImage CutEllipse(Rectangle rec, System.Drawing.Size size)
{
Bitmap bitmap = new Bitmap(size.Width, size.Height);
Image img = bitmapFill;
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(System.Drawing.Point.Empty, size));
}
}return GetBitmapImageBybitmap(bitmap);
}
2.调用
//System.Drawing.Rectangle(左上角X坐标, 左上角Y坐标, 宽, 高)
//System.Drawing.Size(画布的宽, 画布的高)
this.ShotImage.Source = ImageHelper.CutEllipse(new System.Drawing.Rectangle(RouStaX, RouStaY, width, height), new System.Drawing.Size(width, height));