笔记二:画形状


Graphics用来绘图。

用draw来划线。vb.net没有画点的功能。

可以画直接、矩形、椭圆、Bezier、弧、饼(封闭的弧线)。

要注意的是:弧、饼用的是度数(不是弧度),且是顺时间转的角度。



Imports System.Drawing
Imports System.Math
Public Class Form1
    Const pi As Double = 3.14159

    '画点(用一个像素的矩形或两个像素的直接来模拟
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim gr As Graphics = PictureBox1.CreateGraphics
        Dim j As Int32 = 50
        For i As Int32 = 10 To 150
            gr.DrawLine(Pens.Red, i, j, i + 1, j + 1)
            j += 1
        Next
    End Sub

    '用直线构成图
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PictureBox1.Refresh() '清除

        Dim gr As Graphics = PictureBox1.CreateGraphics
        Dim x1, y1, x2, y2, d As Short '起点终点、基准距离
        Dim b, c As Double '真实距离

        d = 60
        For a = 0 To 2 * pi Step pi / 360
            b = d * (1 + 1 / 4 * Cos(12 * a))
            c = b * (1 + Sin(4 * a))
            x1 = 150 + Int(c * Cos(a))  '(150,180)中心点
            y1 = 180 + Int(c * Sin(a))
            x2 = 150 + Int(c * Cos(a + pi / 5))
            y2 = 180 + Int(c * Sin(a + pi / 5))
            gr.DrawLine(Pens.BlueViolet, x1, y1, x2, y2)
        Next
    End Sub

    '椭圆或圆
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        PictureBox1.Refresh()
        Dim gr As Graphics = PictureBox1.CreateGraphics
        gr.DrawEllipse(Pens.Red, New Rectangle(0, 0, 100, 80))
        gr.DrawEllipse(Pens.Aqua, New Rectangle(120, 120, 80, 80))
    End Sub

    '椭圆弧  或圆弧 (是对上面椭圆的部分提取)
    '注意:开始和结束角度是以度为单位,且顺时针方向,下面是从30度到120度
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        PictureBox1.Refresh()
        Dim gr As Graphics = PictureBox1.CreateGraphics
        gr.DrawArc(Pens.Red, New Rectangle(20, 20, 150, 200), 30, 120)
    End Sub

    '封闭椭圆弧线,即饼图
    '参数与arc同,只是成图时是封闭的
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        PictureBox1.Refresh()
        Dim gr As Graphics = PictureBox1.CreateGraphics
        gr.DrawPie(Pens.Red, New Rectangle(20, 20, 150, 200), 30, 120)
    End Sub

    '贝赛尔曲线 Bezier
    '它由四个点:起点、两个中间点(控制)、终点 组成
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        PictureBox1.Refresh()
        Dim gr As Graphics = PictureBox1.CreateGraphics
        gr.DrawBezier(Pens.Brown, 10, 20, 140, 40, 40, 240, 200, 270)
        gr.DrawRectangle(Pens.Red, New Rectangle(200, 40, 80, 170))
    End Sub

    '多边形--不规则形状
    '由多个点来决定,多个点用Points()数组来表达
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        PictureBox1.Refresh()
        Dim gr As Graphics = PictureBox1.CreateGraphics
        Dim p(2) As System.Drawing.Point

        p(0).X = 30 : p(0).Y = 30
        p(1).X = 100 : p(1).Y = 100
        p(2).X = 50 : p(2).Y = 250
        gr.DrawPolygon(Pens.DarkGreen, p)
    End Sub
End Class








  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hi~ 可私信我了解后再进行下载~ 本资源上传时,遗漏了两个文件,分别是:data_filter_keep_order_output_index.hdvp 以及 IntensityImageToPiontsCloudImage.hdvp,购买了该资源的同学,给我留言,我会私信发给你们。 1.基于halcon算法平台; 2.提供深度图源文件以及解压密码; 3.代码预览: */****************************** * @文档名称: 基于点云的平面度测量。 * @作者: hugo * @版本: 1.1 * @日期: 2021-6-20 * @描述: 该方法支持点云的平面的平面度测量。 ********************************/ dev_update_window ('on') dev_get_window (WindowHandle) read_image (imageReal, './replay_38893_2021-6-7.tif') xResolution:=0.06 yResolution:=0.06 zResolution:=0.001 ScaleFactor:=[xResolution,yResolution,zResolution] *采样区域1 create_drawing_object_rectangle2 (300, 120, rad(90), 30, 20, DrawID) set_drawing_object_params (DrawID, 'color', 'forest green') set_drawing_object_params (DrawID, 'line_width', 1) attach_drawing_object_to_window (WindowHandle, DrawID) .......... *平面度 height:=theta/zScale*0.001 *可视化高度差效果 visParamName := ['lut','alpha_0','intensity','color_1'] visParamValue := ['hsi',0.7,'coord_z','yellow'] Labels := ['','平面度:'+height+'mm',''] objs:=[ObjectModel3Ds[2],final_ObjectModel3Ds] visualize_object_model_3d (WindowHandle, objs, [], [], visParamName, visParamValue, 'Edited by AmazingRobot+', [Labels], '', PoseOut) *stop () clear_object_model_3d (plane_balls) for Index := 0 to |final_ObjectModel3Ds|-1 by 1 clear_object_model_3d (final_ObjectModel3Ds[Index]) endfor return () 谢谢您的信任~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值