110,533
社区成员
发帖
与我相关
我的任务
分享
private Bitmap CreateRoundRectImage(Bitmap bmp,RoundStyle style, int Radius, bool Stroke, Color StrokeColor, int StrokeWidth)
{
Bitmap bp =new Bitmap(bmp.Width,bmp.Height );
bp.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);
using (Graphics grfx = Graphics.FromImage(bp))
{
grfx.SmoothingMode = SmoothingMode.HighQuality;
Region rg1 = new Region(PathHelper.CreateRoundRectPath(new Rectangle(0, 0, bmp.Width, bmp.Height),
Radius, style, false));
grfx.Clip = rg1;
grfx.DrawImageUnscaled(bmp, 0, 0);
// 描边
if (Stroke)
{
grfx.ResetClip();
Region rg2 = new Region(PathHelper.CreateRoundRectPath(new Rectangle(StrokeWidth, StrokeWidth, bmp.Width - StrokeWidth * 2, bmp.Height - StrokeWidth * 2),
Radius, style, false));
rg1.Exclude(rg2);
grfx.FillRegion(new SolidBrush(StrokeColor), rg1);
}
}
return bp;
}