å建ä¸ä¸ªåè§GraphicsPath
è¿èå建ä¸ä¸ªRegion
æGraphicsçClipå±æ§è®¾ç½®ä¸ºè¿ä¸ªRegion
ç¶åDrawImageUnScaledç»ä¸å»å°±è¡äº
注æä½ ç»çé£å¼ å¾è¦æå辨ç设置为ååæ¥çå¾ä¸æ ·ï¼å 为DrawImageæ¯æç
§æµé大å°ç»å¶çãä¸æå辨ç设为ä¸æ ·ä¼åºç°ç空ç½æè
ç»ä¸å
¨ã
å
³é®ä»£ç å¦ä¸,顺便æäºä¸ä¸è¾¹
ï¼PathHelper.CreateRoundRectPathæ¯ä¸ä¸ªèªå®ä¹å½æ°ï¼ç¨æ¥å建åè§ç©å½¢è·¯å¾çï¼
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;
}
温馨提示:答案为网友推荐,仅供参考