在vb.net中如何用Graphics画图

2015-05-29 13:03:43  阅读 5964 次 评论 0 条

 

        Dim i As Integer
        Dim k() As Integer
        Dim Bmp
        Dim Gra

        bmp = New Bitmap(640, 480) '定义Bitmap对象
        gra = Graphics.FromImage(bmp) '获取Graphices对象
        Me.PictureBox1.Image = Bmp '让画出来的图片显示在窗体上的pic控件上
        '定义画线用的画笔
        Dim ppen As Pen = New Pen(Color.Black, 1)
        '定义写字用的刷子
        Dim dotUserBrush As SolidBrush = New SolidBrush(Color.Blue)


        '画线
        For i = 10 To 1000 Step 3
            Gra.DrawLine(ppen, i, 100 + 1 * i, i * 2, 100 + 100 * i) '最上头的横线
        Next

        '''''''
        Dim FFamily As FontFamily = New FontFamily("宋体")
        Dim font As Font = New Font(FFamily, "12", FontStyle.Regular, FontStyle.Italic, GraphicsUnit.Pixel)
        Dim text As String = "你输出的文字"
        Dim solidbrush As SolidBrush = New SolidBrush(Color.Black)

        Dim pr As PointF
        '在图片上写字
        pr = New PointF(10, 50)
        Gra.DrawString(text, font, solidbrush, pr)

        '画矩形
        Gra.FillRectangle(solidbrush, 300, 400, 20, 20)


        '打印图片标题
        text = "销售操作图"
        pr = New PointF(10, 10)
        font = New Font(FFamily, "15", FontStyle.Bold, FontStyle.Regular, FontStyle.Italic, GraphicsUnit.Pixel)
        Gra.DrawString(text, font, solidbrush, pr)

        '画椭圆
        Gra.FillEllipse(solidbrush, 200, 300, 50, 60)

        '保存图片的方法
        'bmp.Save("c:\genImage.jpg")

        'Return "genImage.jpg"
    End Sub

 

本文地址:http://jinesc.cn/?id=136
免责声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?