How can I crop an image to a circle?

后端 未结 2 1558
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 07:51

I\'m trying to crop an image to a circle, where the area outside of the circle is white.

The new image dimensions would be the same as the original, just effectively

2条回答
  •  悲&欢浪女
    2021-01-14 08:24

    You could achieve this with HTML and CSS3.

    HTML

    CSS

    .circular {
    width: 300px;
    height: 300px;
    border-radius: 150px;
    -webkit-border-radius: 150px;
    -moz-border-radius: 150px;
    background: url(http://link-to-your/image.jpg) no-repeat;
    }
    

    So for your project you could add a div with runat="server", give it a CSS-class and an ID and programatically add the background to the one you want.

    C#

    yourDiv.Attributes.Add("style", "background: url(" + yourLink + ") no-repeat);
    

    Check this link for more info. http://bavotasan.com/2011/circular-images-with-css3/

提交回复
热议问题