设置Region属性:
创新互联建站是专业的祁东网站建设公司,祁东接单;提供网站制作、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行祁东网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Dim path As New System.Drawing.Drawing2D.GraphicsPath
path.AddEllipse(0, 0, 400, 300)
Region = New Region(path)
新建一个Winform,拖两个图片框。图片框1在设计器中选择一个图片(尺寸在图片框容纳为佳)。如下代码测试通过:
private void button1_Click(object sender, EventArgs e)
{
Image img1 = this.pictureBox1.Image;
Image img2 = CropToCircle(img1);
this.pictureBox2.Image = img2;
}
public Image CropToCircle(Image img1)
{
Image img2 = new Bitmap(img1.Width, img1.Height,
img1.PixelFormat);
Graphics g = Graphics.FromImage(img2);
using (Brush br =
new SolidBrush(SystemColors.Control))//背景色
{
g.FillRectangle(br, 0, 0,
img2.Width, img2.Height);
}
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, img2.Width, img2.Height);
g.SetClip(path);
g.DrawImage(img1, 0, 0);
return img2;
}
'我给你找到了,设置region属性就可
Private Sub PictureBox1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles PictureBox1.DoubleClick
If PictureBox1.Region Is Nothing Then
Dim path As New System.Drawing.Drawing2D.GraphicsPath
path.AddEllipse(0, 0, 200, 200)
PictureBox1.Region = New Region(path)
Else
PictureBox1.Region = Nothing
End If
End Sub
'这个双击图片框使其变形,通过GraphicsPath对象可以作出各种形态来,比如可作出文字形状
Dim stringText As String = "我是谁"
Dim family As New FontFamily("Arial")
Dim myfontStyle As Integer = CInt(FontStyle.Italic)
Dim emSize As Integer = 86
Dim origin As New Point(20, 20)
Dim format As StringFormat = StringFormat.GenericDefault
path.AddString(stringText, family, myfontStyle, emSize, _
origin, format)
PictureBox1.Region = New Region(path)