窗体上添加一个按钮,在该按钮的单击事件里编写代码如下:
镇巴ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'声明窗体的Me.CreateGraphics对象
Dim MyGraphics As Graphics = Me.CreateGraphics
Dim Cx As Integer = 150 '圆心的X坐标
Dim Cy As Integer = 150 '圆心的Y坐标
Dim R As Integer '圆的半径
'绘制半径为R的圆
For R = 5 To 100 Step 5
MyGraphics.DrawEllipse(Pens.Black, New Rectangle(Cx - R, Cy - R, 2 * R, 2 * R))
Next
End Sub
‘用黑色画笔绘制一组同心圆,半径从5开始,增量为5。
说明:
DrawEllipse是VB.Net的Graphics类的绘制椭圆的方法;他有几种格式,上面使用的是一种;
DrawEllipse(画笔的颜色,绘制椭圆所需要的矩形区域)
其中:绘制椭圆所需要的矩形区域,如果被定义为正方形,就演变成绘制圆,定义该区域由死个数值确定,第1个数值,确定该区域左上角的X坐标,第2个数值,确定该区域左上角的Y坐标,第3个数值,确定该区域的宽度,第4个数值,确定该区域的高度。
例如1:
DrawEllipse(Pens.Black, New Rectangle(150, 150, 50, 50))
就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),边长为50的正方形里绘制内切圆。理解了是在正方形里绘制内切圆,就可以通过数学计算,知道如何绘制了。
同理例如2:
DrawEllipse(Pens.Black, New Rectangle(150, 150, 100, 50))
就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),长轴为100,短轴为50的内切椭圆。
'我给你找到了,设置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)
设置Region属性:
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;
}