css怎么弄正方形靠右,css里怎么实现正方形下边斜着图形

C#图片圆角问题,怎么实现图片四个角真正透明

创建一个圆角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;

}

收起

6f93e2c92fc5e58e2ec18df1db0b9f08.png

阅读全文

9ded402a52cdd2b9481e864a5093252c.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值