vb.net多功能白板(集成:绘图,编辑,批注,橡皮,图片处理,拍摄,裁剪,旋转等功能

news2024/11/26 15:32:47

根据上一次的自定义白板,我已经更新了很多内容了

这一次打算再细一点

初始化程序:所有的整体变量(作者提醒,请不要直接照抄代码,可以和作者发的文件进行学习和参考

    Public ListOfPen As New List(Of Bitmap)
    Public ListOfBack As New List(Of Bitmap)
    'Function SetImage(i As Integer, picL As PicList)
    '    PicLists.Item(i) = picL
    'End Function
    'Public Function AddImage(PenImg As Bitmap, BackBmp As Bitmap)
    '    PicLists.Add(PicListIndex, New PicList(PenImg, BackBmp))
    '    PicListIndex += 1
    'End Function
    Public backbmp As Bitmap
    Public isback As Boolean
    Dim BodColor As Color
    Dim Shadow As Color
    ''' <summary>
    ''' MouseMove
    ''' </summary>
    Dim MoveDown As Boolean = False
    Dim CurrX As Integer
    Dim CurrY As Integer
    Dim MousX As Integer
    Dim MousY As Integer
    Dim x1, x2, y1, y2 As Integer
    ''' <summary>
    ''' DrawList
    ''' </summary>
    Public g1 As Graphics
    Public penImg As Bitmap
    Dim listPoint As New List(Of Point)
    Dim ispaint As Boolean = True
    Dim g As Graphics
    ''' <summary>
    ''' Functions and Pen
    ''' </summary>
    Dim func As Integer = 0
    Dim pen As New Pen(Color.Red, 2)
    ''' <summary>
    ''' string
    ''' </summary>
    Dim s As String
    Dim TxtFont As New Font("微软雅黑", 30, FontStyle.Regular)
    Dim fdlg As New FontDialog
    ''' <summary>
    ''' temp
    ''' </summary>
    Public tmp As Bitmap

    ''' <summary>
    ''' Brush and Index
    ''' </summary>

    Dim Filled As Boolean
    Public index As Integer = 0
    ''' <summary>
    ''' 竖版文字还是横版
    ''' </summary>
    Dim StrFormat As Boolean = True
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    'SetStyle(ControlStyles.UserPaint, True)
    'SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    'SetStyle(ControlStyles.DoubleBuffer, True)
    BodColor = Color.Red
    Shadow = Color.LightGray
    Filled = False
    Panel3.Visible = False
    Panel1.Visible = False
    Pic2.Visible = False
    Pic.Location = New Point(0, 0)
    Pic.Width = Screen.PrimaryScreen.Bounds.Width
    Pic.Height = Screen.PrimaryScreen.Bounds.Height
    penImg = New Bitmap(Pic.Width, Pic.Height)
    backbmp = New Bitmap(penImg)
    g1 = Graphics.FromImage(penImg)
    g1.Clear(Color.Transparent)
    g1.SmoothingMode = SmoothingMode.HighQuality
    ' g1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
    Pic.Image = penImg
    pen.StartCap = LineCap.Round
    pen.EndCap = LineCap.Round
    isback = False
    g = Pic.CreateGraphics
    g.SmoothingMode = SmoothingMode.HighQuality
    ListOfBack.Add(New Bitmap(penImg))
    ListOfPen.Add(New Bitmap(penImg))
    If My.Application.CommandLineArgs().Count > 0 Then
        Try
            For i = 0 To My.Application.CommandLineArgs().Count - 1
                Dim bmp As New Bitmap(My.Application.CommandLineArgs(i))
                ListOfBack.Add(New Bitmap(bmp))
                ListOfPen.Add(New Bitmap(bmp))
                Form5.penimg = ListOfPen.ToArray
                Form5.backbmp = ListOfBack.ToArray
                Form5.Show()
                Form5.TopMost = True
            Next
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & "————————————————————" & vbCrLf & "不支持的文件")
        End Try

        'penImg = New Bitmap(My.Application.CommandLineArgs(0))
        'Pic.Width = penImg.Width
        'Pic.Height = penImg.Height
        'g1 = Graphics.FromImage(penImg)
        ''g1.Clear(Color.Transparent)
        'g1.SmoothingMode = SmoothingMode.HighQuality
        'Pic.Image = penImg
        'backbmp = New Bitmap(penImg)
        'isback = True
        'pen.StartCap = LineCap.Round
        'pen.EndCap = LineCap.Round
    End If

End Sub

BodColor = Color.Red
Shadow = Color.LightGray
还没做到实例中,暂不考虑

 Pic.Width = Screen.PrimaryScreen.Bounds.Width
Pic.Height = Screen.PrimaryScreen.Bounds.Height
penImg = New Bitmap(Pic.Width, Pic.Height)
backbmp = New Bitmap(penImg)

将白板初始化为屏幕分辨率

g1 = Graphics.FromImage(penImg)
g1.Clear(Color.Transparent)
g1.SmoothingMode = SmoothingMode.HighQuality

定义Graphics类

pen.StartCap = LineCap.Round
pen.EndCap = LineCap.Round
isback = False
g = Pic.CreateGraphics
g.SmoothingMode = SmoothingMode.HighQuality
ListOfBack.Add(New Bitmap(penImg))
ListOfPen.Add(New Bitmap(penImg))
定义画笔,g1是针对PenImg的,而g针对pic控件(pictureBox)

If My.Application.CommandLineArgs().Count > 0 Then

注意,这是用来接受用户吧文件拖到应用程序图标上,而它接受的命令数组是文件的路径,好,我们直接导入库

Try
    For i = 0 To My.Application.CommandLineArgs().Count - 1
        Dim bmp As New Bitmap(My.Application.CommandLineArgs(i))
        ListOfBack.Add(New Bitmap(bmp))
        ListOfPen.Add(New Bitmap(bmp))
        Form5.penimg = ListOfPen.ToArray
        Form5.backbmp = ListOfBack.ToArray
        Form5.Show()
        Form5.TopMost = True
    Next
Catch ex As Exception
    MsgBox(ex.Message & vbCrLf & "————————————————————" & vbCrLf & "不支持的文件")
End Try

也可以使用For Each逐个导入。。。

我在测试的时候呢,发现一个问题,是我在导入多个图片的时候他会自己打开库(Form5),原因也很简单,我们看上面的代码段,我直接把Form5.Show写在了For循环里面了😂

我们把Form5的4行搬到For循环外面就可以了。。。

别头晕,还有好多呢。。。

先介绍Pic(PictureBox控件,用来呈现用户批注编辑的,用户可以随意的移动控件,在控件上面画画,擦除,那可想而知,最多的代码肯定在Pic.MouseMove和Pic.MouseUp这两个事件里面。

定义画笔(刷子)

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    If func = 0 Then
        Dim cdlg As New ColorDialog
        If cdlg.ShowDialog() = DialogResult.OK Then
            Pic.BackColor = cdlg.Color
        End If
    End If
    func = 0
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If func = 1 Then
        Panel1.Visible = True
        Panel1.Location = New Point(Button3.Location.X + Panel2.Location.X, Button3.Location.Y + Panel2.Location.Y - 100)
    End If
    func = 1

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    func = 2
End Sub

Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
    func = 3
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    func = 4
End Sub

Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
    func = 5
End Sub

Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    func = 6
End Sub

Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    func = 7
End Sub

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
    func = 8
    s = InputBox("输入文字", "自定义白板")
End Sub

0是移动,1是批注,2是橡皮,3是椭圆,4是矩形,5是直线,6是正方形。7是圆,8是文字,9是插入一张图。

MouseMove主要是在Pic上面实时更新用户绘画的数据,直到MouseUp的时候被绘制到penImg上面,PenImg是实际图片,而backbmp是初始图片,一般我们不去动初始图片

使用

Pic.Invalidate()
Pic.Update()

让控件貌似处于实时更新的状态。

Filled As Boolean 是判断用户是否需要实心图案

ok直接贴出MouseMove和MouseUp事件的代码,千万不要被吓。

MouseMove

Private Sub Pic_MouseMove(sender As Object, e As MouseEventArgs) Handles Pic.MouseMove
        g = Pic.CreateGraphics
        Dim w As Double = Math.Abs(x1 - e.X)
        Dim h As Double = Math.Abs(y1 - e.Y)
        Dim l As Double = Math.Sqrt(w * w + h * h)
        If MoveDown = True Then
            If ispaint = True Then
                Pic.Invalidate()
                Pic.Update()
            End If

            If func = 0 Then
                CurrX = Pic.Left - MousX + e.X
                CurrY = Pic.Top - MousY + e.Y
                Pic.Location = New Point(CurrX, CurrY)

            ElseIf func = 1 Then
                If Filled = False Then
                    listPoint.Add(New Point(e.X, e.Y))
                    If listPoint.Count < 3 AndAlso listPoint.Count > 1 Then
                        g.DrawLine(pen, listPoint(0), listPoint(1))
                    End If
                    If listPoint.Count > 2 Then
                        g.DrawCurve(pen, listPoint.ToArray(), 0.1)
                    End If
                Else
                    listPoint.Add(New Point(e.X, e.Y))
                    If listPoint.Count > 2 Then
                        g.DrawCurve(pen, listPoint.ToArray(), 0.1)
                    End If
                End If

            ElseIf func = 2 Then
                If isback = True Then
                    x1 = e.X
                    y1 = e.Y
                    g1.CompositingMode = CompositingMode.SourceCopy
                    Try
                        g1.DrawImage(backbmp.Clone(New Rectangle(x1 - 25, y1 - 25, 50, 50), Imaging.PixelFormat.Format32bppArgb), e.X - 25, e.Y - 25)
                    Catch ex As Exception
                    End Try

                    Pic2.Location = New Point(x1 + Pic.Location.X - 25, y1 + Pic.Location.Y - 25)
                    Pic2.Width = 50
                    Pic2.Height = 50

                Else
                    x1 = e.X
                    y1 = e.Y
                    g1.CompositingMode = CompositingMode.SourceCopy
                    g1.FillRectangle(New SolidBrush(Color.Transparent), New Rectangle(x1 - 25, y1 - 25, 50, 50))
                    Pic2.Location = New Point(x1 + Pic.Location.X - 25, y1 + Pic.Location.Y - 25)
                    Pic2.Width = 50
                    Pic2.Height = 50

                End If
                'Dim l As Double = Math.Sqrt(Math.Abs(x1 - e.X) * Math.Abs(x1 - e.X) + Math.Abs(y1 - e.Y) * Math.Abs(y1 - e.Y))

                'g.DrawEllipse(pen, New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
            ElseIf func = 3 Then
                If Filled = False Then
                    g.DrawEllipse(pen, New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
                    g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                    g.DrawRectangle(New Pen(Color.Red, 1), New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
                Else
                    g.FillEllipse(New SolidBrush(pen.Color), New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
                    g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                    g.DrawRectangle(New Pen(Color.Red, 1), New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
                End If

            ElseIf func = 4 Then
                If Filled = False Then
                    g.DrawRectangle(pen, PointList(New Point(x1, y1), New Point(e.X, e.Y)))
                    'g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                Else
                    g.FillRectangle(New SolidBrush(pen.Color), PointList(New Point(x1, y1), New Point(e.X, e.Y)))
                End If

            ElseIf func = 5 Then

                g.DrawLine(pen, x1, y1, e.X, e.Y)

            ElseIf func = 6 Then
                If Filled = False Then                    '
                    g.DrawRectangle(pen, PointListT(New Point(x1, y1), New Point(e.X, e.Y)))
                    'g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                Else
                    g.FillRectangle(New SolidBrush(pen.Color), PointListT(New Point(x1, y1), New Point(e.X, e.Y)))
                End If
            ElseIf func = 7 Then
                If Filled = False Then
                    g.DrawEllipse(pen, New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
                    g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                    g.DrawRectangle(New Pen(Color.Red, 1), New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
                Else
                    g.FillEllipse(New SolidBrush(pen.Color), New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
                    g.DrawLine(New Pen(Color.Red, 1), New Point(x1, y1), New Point(e.X, e.Y))
                    g.DrawRectangle(New Pen(Color.Red, 1), New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
                End If

            ElseIf func = 8 Then

                If StrFormat = True Then
                    Dim size As Size = GetStringSize(s, TxtFont, New StringFormat(1))
                    'If Check1.Checked = False Then
                    g.DrawString(s, TxtFont, New SolidBrush(pen.Color), e.X, e.Y)
                    'Else
                    ' g.DrawString(s, TxtFont, New SolidBrush(Color.FromArgb(NumAlpha.Value, Shadow)), e.X + Num1.Value, e.Y + Num2.Value)
                    '     g.DrawString(s, TxtFont, New SolidBrush(pen.Color), e.X, e.Y)
                    '     Dim path As New GraphicsPath()
                    '     path.AddString(s, TxtFont.FontFamily, TxtFont.Style, g.DpiY * TxtFont.Size / 72, New Rectangle(e.X, e.Y, size.Width, size.Height), New StringFormat(1))
                    '     g.DrawPath(New Pen(BodColor, NumWidth.Value), path)
                    ' End If
                    g.DrawLine(New Pen(pen.Color, 1), New Point(0, e.Y), New Point(Pic.Width, e.Y))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(e.X, 0), New Point(e.X, Pic.Height))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(0, e.Y + size.Height), New Point(Pic.Width, e.Y + size.Height))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(e.X + size.Width, 0), New Point(e.X + size.Width, Pic.Height))
                Else
                    Dim size As Size = GetStringSize(s, TxtFont, New StringFormat(2))
                    g.DrawString(s, TxtFont, New SolidBrush(pen.Color), e.X, e.Y, New StringFormat(2))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(0, e.Y), New Point(Pic.Width, e.Y))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(e.X, 0), New Point(e.X, Pic.Height))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(0, e.Y + size.Height), New Point(Pic.Width, e.Y + size.Height))
                    g.DrawLine(New Pen(pen.Color, 1), New Point(e.X + size.Width, 0), New Point(e.X + size.Width, Pic.Height))
                End If
            ElseIf func = 9 Then
                g.DrawImage(tmp, e.X, e.Y)
            End If
            'Pic.Image = penImg

        End If
    End Sub

MouseUp

Private Sub Pic_MouseUp(sender As Object, e As MouseEventArgs) Handles Pic.MouseUp
    g1.CompositingMode = CompositingMode.SourceCopy
    g1 = Graphics.FromImage(penImg)
    g1.SmoothingMode = SmoothingMode.HighQuality
    MoveDown = False
    Pic2.Visible = False
    Dim w As Double = Math.Abs(x1 - e.X)
    Dim h As Double = Math.Abs(y1 - e.Y)
    Dim l As Double = Math.Sqrt(w * w + h * h)
    If func = 1 Then
        g1 = Graphics.FromImage(penImg)
        g1.SmoothingMode = SmoothingMode.HighQuality
        If Filled = False Then
            listPoint.Add(New Point(e.X, e.Y))
            If listPoint.Count < 3 AndAlso listPoint.Count > 1 Then
                g1.DrawLine(pen, listPoint(0), listPoint(1))
            End If
            If listPoint.Count > 2 Then
                g1.DrawCurve(pen, listPoint.ToArray(), 0.1)
            End If
        Else
            If listPoint.Count > 2 Then
                g1.FillClosedCurve(New SolidBrush(pen.Color), listPoint.ToArray(), 0.1)
            End If
        End If
        ispaint = True
        Pic.Invalidate()
        Pic.Update()
    End If
    If func = 3 Then
        If Filled = False Then
            g1.DrawEllipse(pen, New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
        Else
            g1.FillEllipse(New SolidBrush(pen.Color), New Rectangle(x1 - w, y1 - h, 2 * w, 2 * h))
        End If
    End If
    If func = 4 Then
        If Filled = False Then
            g1.DrawRectangle(pen, PointList(New Point(x1, y1), New Point(e.X, e.Y)))
        Else
            g1.FillRectangle(New SolidBrush(pen.Color), PointList(New Point(x1, y1), New Point(e.X, e.Y)))
        End If
    End If
    If func = 5 Then
        'Pic.Invalidate()
        g1.DrawLine(pen, x1, y1, e.X, e.Y)
    End If
    If func = 6 Then
        If Filled = False Then
            g1.DrawRectangle(pen, PointListT(New Point(x1, y1), New Point(e.X, e.Y)))
        Else
            g1.FillRectangle(New SolidBrush(pen.Color), PointListT(New Point(x1, y1), New Point(e.X, e.Y)))
        End If
    End If
    If func = 7 Then
        If Filled = False Then
            g1.DrawEllipse(pen, New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
        Else
            g1.FillEllipse(New SolidBrush(pen.Color), New Rectangle(x1 - l, y1 - l, 2 * l, 2 * l))
        End If

    End If
    If func = 8 Then
        If StrFormat = True Then
            g1 = Graphics.FromImage(penImg)
            g1.SmoothingMode = SmoothingMode.HighQuality
            g1.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
            g1.DrawString(s, TxtFont, New SolidBrush(pen.Color), New PointF(e.X, e.Y))
        Else
            g1 = Graphics.FromImage(penImg)
            g1.SmoothingMode = SmoothingMode.HighQuality
            g1.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
            g1.DrawString(s, TxtFont, New SolidBrush(pen.Color), New PointF(e.X, e.Y), New StringFormat(2))
        End If
    End If
    If func = 9 Then
        g1.DrawImage(tmp, e.X, e.Y)
    End If
    'MsgBox(index)
    ListOfPen(index) = penImg
    ListOfBack(index) = backbmp

    listPoint.Clear()
    Pic.Image = penImg
End Sub

文字部分GetSize是通过一个函数来解决的

Public Function GetStringSize(s As String, font As Font, sf As StringFormat) As Size
    Dim size As New Size(CInt(g.MeasureString(s, font, 9999, sf).Width), CInt(g.MeasureString(s, font, 9999, sf).Height))
    Return size
End Function

如何实现文件拖入窗体然后在库里面打开的效果呢?

Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
    Dim filepath As String() = e.Data.GetData(DataFormats.FileDrop)
    For i = 0 To filepath.Count - 1
        Dim fs As New FileStream(filepath(i), FileMode.Open, FileAccess.Read)
        Dim bmp As New Bitmap(fs)
        ListOfBack.Add(New Bitmap(bmp))
        ListOfPen.Add(New Bitmap(bmp))
        fs.Close()
    Next
End Sub
Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
    If e.Data.GetDataPresent(DataFormats.FileDrop) = True Then
        e.Effect = DragDropEffects.Copy
    Else
        e.Effect = DragDropEffects.None
    End If
End Sub

我在画长方形的时候只能从左上滑倒右下,其实作者编了一个函数专门来格式化2个点,然后转换为Rectangle类

Public Function PointList(p1 As Point, p2 As Point) As Rectangle
    Dim p3 As Point
    Dim p4 As Point
    Dim width As Integer
    Dim height As Integer
    Dim LeftTop As Point

    If p1.X < p2.X AndAlso p1.Y < p2.Y Then
        p3 = New Point(p2.X, p1.X)
        p4 = New Point(p1.X, p2.Y)
        width = p3.X - p1.X
        height = p4.Y - p1.Y
        LeftTop = p1
    ElseIf p1.X > p2.X AndAlso p1.Y < p2.Y Then
        p3 = New Point(p1.X, p2.Y)
        p4 = New Point(p2.X, p1.Y)
        width = p1.X - p4.X
        height = p2.Y - p4.Y
        LeftTop = p4
    ElseIf p1.X > p2.X AndAlso p1.Y > p2.Y Then
        p3 = New Point(p1.X, p2.X)
        p4 = New Point(p2.X, p1.Y)
        width = p3.X - p2.X
        height = p4.Y - p2.Y
        LeftTop = p2
    ElseIf p1.X < p2.X AndAlso p1.Y > p2.Y Then
        p3 = New Point(p2.X, p1.Y)
        p4 = New Point(p1.X, p2.Y)
        width = p2.X - p4.X
        height = p1.Y - p4.Y
        LeftTop = p4
    End If
    Return New Rectangle(LeftTop, New Size(width, height))
End Function

正方形则同理

Public Function PointListT(p1 As Point, p2 As Point) As Rectangle
    Dim p3 As Point
    Dim p4 As Point
    Dim width As Integer
    Dim height As Integer
    Dim LeftTop As Point
    If p1.X < p2.X AndAlso p1.Y < p2.Y Then
        p3 = New Point(p2.X, p1.X)
        p4 = New Point(p1.X, p2.Y)
        width = p3.X - p1.X
        height = width
        LeftTop = p1
    ElseIf p1.X > p2.X AndAlso p1.Y < p2.Y Then
        p3 = New Point(p1.X, p2.Y)
        p4 = New Point(p2.X, p1.Y)
        width = p1.X - p4.X
        height = width
        LeftTop = p4
    ElseIf p1.X > p2.X AndAlso p1.Y > p2.Y Then
        p3 = New Point(p1.X, p2.X)
        p4 = New Point(p2.X, p1.Y)
        width = p3.X - p2.X
        height = width
        LeftTop = New Point(p1.X - width, p1.Y - width)
    ElseIf p1.X < p2.X AndAlso p1.Y > p2.Y Then
        p3 = New Point(p2.X, p1.Y)
        p4 = New Point(p1.X, p2.Y)
        width = p2.X - p4.X
        height = width
        LeftTop = New Point(p1.X, p1.Y - width)
    End If
    Return New Rectangle(LeftTop, New Size(width, height))
End Function

这两段具体的解释请看:vb.net给窗体截图 (VB.net,仿照Windows原版截图,类库——9)_大Mod_abfun的博客-CSDN博客_vb.net 屏幕截图里面有详细的解释。

一个好消息就是在透明的bitmap上面话文字的时候就不会有黑边了:Drawing.Text.TextRenderingHint.AntiAliasGridFit

If func = 8 Then
    If StrFormat = True Then
        g1 = Graphics.FromImage(penImg)
        g1.SmoothingMode = SmoothingMode.HighQuality
        g1.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
        g1.DrawString(s, TxtFont, New SolidBrush(pen.Color), New PointF(e.X, e.Y))
    Else
        g1 = Graphics.FromImage(penImg)
        g1.SmoothingMode = SmoothingMode.HighQuality
        g1.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
        g1.DrawString(s, TxtFont, New SolidBrush(pen.Color), New PointF(e.X, e.Y), New StringFormat(2))
    End If
End If

还有更多想要了解的,请亲自下载源代码研究和使用,目前还有一点功能没有实现

好,我们来看Form2,摄像机类(窗体),如果你的摄像机有问题的话请不要责怪代码写的不好,我在其他电脑上面试过,没有问题

此代码需要第三方类库支持:Aforge(具体请看源代码

Imports System.ComponentModel
Imports AForge.Video.DirectShow

Public Class Form2
    Dim videodevice As FilterInfoCollection
    Dim videoSource As VideoCaptureDevice
    Dim indexof As Integer
    Dim Capabilities As VideoCapabilities


    Public Sub Start(index As Integer)
        videodevice = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        Listvids.Items.Clear()
        If videodevice.Count = 0 Then
            MsgBox("没有摄像头")
        Else
            For Each d As FilterInfo In videodevice
                Listvids.Items.Add(d.Name)
            Next
            VideoPlayer.SignalToStop()
            VideoPlayer.WaitForStop()
            videoSource = New VideoCaptureDevice(videodevice(index).MonikerString)
            VideoPlayer.VideoSource = videoSource
            'videoSource.
            VideoPlayer.Start()
            Try
                Capabilities = videoSource.SnapshotCapabilities(index)
                VideoPlayer.Width = Capabilities.FrameSize.Width
                VideoPlayer.Height = Capabilities.FrameSize.Height
            Catch ex As Exception
            End Try



        End If
    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Start(0)
    End Sub

    Private Sub Listvids_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Listvids.SelectedIndexChanged
        Try
            'MsgBox(indexof)
            VideoPlayer.Stop()
            indexof = Listvids.SelectedIndex
            Start(indexof)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Form2_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        VideoPlayer.Stop()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Pic.Image = VideoPlayer.GetCurrentVideoFrame
    End Sub
    Dim MoveDown As Boolean = False
    Dim CurrX As Integer
    Dim CurrY As Integer
    Dim MousX As Integer
    Dim MousY As Integer
    Private Sub VideoPlayer_MouseDown(sender As Object, e As MouseEventArgs) Handles VideoPlayer.MouseDown
        MousX = e.X
        MousY = e.Y
        MoveDown = True
    End Sub

    Private Sub VideoPlayer_MouseMove(sender As Object, e As MouseEventArgs) Handles VideoPlayer.MouseMove
        If MoveDown = True Then
            CurrX = VideoPlayer.Left - MousX + e.X
            CurrY = VideoPlayer.Top - MousY + e.Y
            VideoPlayer.Location = New Drawing.Point(CurrX, CurrY)
        End If
    End Sub

    Private Sub VideoPlayer_MouseUp(sender As Object, e As MouseEventArgs) Handles VideoPlayer.MouseUp
        MoveDown = False
    End Sub

    Private Sub Form2_DoubleClick(sender As Object, e As EventArgs) Handles Me.DoubleClick
        VideoPlayer.Location = New Point(0, 0)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            With Form1
                .penImg = New Bitmap(Pic.Image)
                .Pic.Width = Pic.Image.Width
                .Pic.Height = Pic.Image.Height
                .g1 = Graphics.FromImage(Form1.penImg)
                .g1.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
                .Pic.Image = Pic.Image
                .backbmp = New Bitmap(Pic.Image)
                .isback = True
                .Pic.Location = New Point(0, 0)
                .ListOfBack.Add(New Bitmap(Pic.Image))
                .ListOfPen.Add(New Bitmap(Pic.Image))
                .index = .ListOfPen.Count - 1
            End With
            Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub Form2_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Panel1.Location = New Point((Width - Panel1.Width) / 2, Height - 120)
        Pic.Location = New Point(Width - Pic.Width - 50, Height - 280)
        Listvids.Location = New Point(Width - Listvids.Width - 50, Height - 480)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim p = VideoPlayer.GetCurrentVideoFrame
        Dim save As New SaveFileDialog
        save.Filter = "All .net Picture Files|*.jpg;*.png;*.bmp;*.ico;*.jpeg;*.*"
        save.InitialDirectory = Application.StartupPath
        Dim a = save.ShowDialog
        If a = DialogResult.OK Then
            p.Save(save.FileName)
        End If
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Pic.Image = Clipboard.GetImage
        Form1.ListOfBack.Add(New Bitmap(Clipboard.GetImage))
        Form1.ListOfPen.Add(New Bitmap(Clipboard.GetImage))
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Try
            Clipboard.SetImage(Pic.Image)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Form1.WindowState = FormWindowState.Minimized
        Close()
        Dim img As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
        Dim g As Graphics
        g = Graphics.FromImage(img)
        g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
        Form3.pic = img
        Form1.WindowState = FormWindowState.Maximized
        Form3.ShowDialog()
        'Form1.AddImage(img, img)
    End Sub
End Class

源代码文件下载:1、查看我CSDN上传的资源

2、百度网盘:链接:https://pan.baidu.com/s/1mlwiJxAMemmXAw4Qk9YSZQ?pwd=2333 
提取码:2333

 

如要转载,请与作者联系,未经许可,不准转载,最近还是发现有大量转载的情况!!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/153795.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ArcGIS如何进行自动矢量化操作

这里我们在网络上找一幅高中地理课本上看的等高线图给大家能进行操作演示。 等高线图 01 地理配准 1、定义投影 给数据框定义一个投影&#xff0c;右键Layers>Properties>Coordinate System>Projected Coordinate Systems>Gauss Kruger>Beijing1954> Be…

雅思经验总结(1)

听力技巧&#xff1a;听sections 3就是看你何时进入状态&#xff0c;还有审题&#xff0c;之后就是听but&#xff0c;其他的转折词什么yet because however什么都非常的少&#xff0c;最主要的还是but&#xff0c;注意bus之后的话&#xff0c;其余的什么细节题就是说还要听懂文…

Biome-BGC生态系统模型区域模拟

Biome-BGC是利用站点描述数据、气象数据和植被生理生态参数&#xff0c;模拟日尺度碳、水和氮通量的有效模型&#xff0c;其研究的空间尺度可以从点尺度扩展到陆地生态系统。在Biome-BGC模型中&#xff0c;对于碳的生物量积累&#xff0c;采用光合酶促反应机理模型计算出每天的…

Java面向对象进阶之static

目录static静态关键字static&#xff1a;修饰成员变量&#xff0c;内存机制static是什么、修饰成员变量的方法总结static修饰成员变量的内存原理static&#xff1a;修饰成员方法、内存机制static修饰成员方法的基本用法总结static修饰成员方法的内存原理static的注意事项static…

计算机组成原理习题二

计算机组成原理习题二 文章目录计算机组成原理习题二1、某指令系统的指令格式如下&#xff1a;答案&#xff1a;(1)152301Q1101 010011 000 001I10&#xff0c;I21&#xff0c;Z/C0&#xff0c;D/I0&#xff0c;故为变址寄存器2寻址&#xff0c;EA(I2)A063215301063516Q。 (4)…

大咖年终“讲” 维视教育李明睿——制造业转型升级下需要重新定义人才培养

数字化转型迫在眉睫建设应用型大学风潮正涌制造企业在推进智能制造和数字化转型进程中&#xff0c;衍生出大量人才需求。据人社部、工信部发布的《制造业人才发展规划指南》显示&#xff0c;中国制造业10大重点领域人才缺口2025年将接近3000万人&#xff0c;缺口率高达48&#…

流媒体基础-RTCP

1、RTCP的封装 RTP需要RTCP为其服务器质量提供保证&#xff0c;周期性发送 RTCP的主要功能是&#xff1a;服务质量的监视、反馈&#xff08;QoS&#xff09;、媒体间的同步&#xff08;Sync&#xff09;&#xff0c;以及多播组中成员的标识。在RTP会话期间&#xff0c;各参与者…

Lichee_RV学习系列---认识Lichee_RV、环境搭建和编译第一个程序

系列文章目录 文章目录系列文章目录前言一、认识Lichee RV1、D1-H 芯片2、Lichee RV开发板3、系统镜像二、Lichee RV 固件烧录1、要求基本硬件2、基本资料下载3、固件烧录在这里插入图片描述三、连接上开发板1、ADB方式连接a&#xff1a;ADB下载b&#xff1a;ADB连接c&#xff…

孙溟㠭篆刻《无有中无尽藏》

《无有中无尽藏》孙溟㠭篆刻 无一物中无尽藏&#xff0c;是说当“我执”袪除&#xff0c;仅余“真如”时&#xff0c;便可以理解“无尽藏”。虽然身上没有东西&#xff0c;但是其实世人身上藏了所有的东西。“无心”亦是有心&#xff0c;心中富足。所以当人祛除心中的偏执&…

自动语音识别(ASR)研究综述

自动语音识别ASR研究综述 一、语言识别基础知识 从语音系统识别构成来讲&#xff0c;一套完整的语音识别系统包括&#xff1a;预处理、特征提取、声学模型、语言模型、以及搜索算法等模块&#xff0c;具体结构示意图如下所示: 特征提取&#xff08;MFCC声学特征&#xff09…

Error handling response: TypeError: self.processResponse is not a function

问题背景 &#xff1a; 自己在搭建 Vue 初始模板架子的时候 &#xff0c; 解决完 router 路由的报错问题后 &#xff0c; 控制台还剩下一个显眼的 Error 红色 Bug &#xff0c; 不解决的话看着难受 &#xff0c; 盘它 &#xff01; 点击报错内容后进入 &#xff1a; Error h…

redis应用笔记

1.登录服务 在登陆服务中,如果将数据全部存储到tomcat中,当存在多个tomcat的时候,数据是无法同步的,这就导致了数据的共享问题: 1、每台服务器中都有完整的一份session数据&#xff0c;服务器压力过大。 2、session拷贝数据时&#xff0c;可能会出现延迟 解决办法就是采用redi…

SpringBoot整合Redis实现优惠券秒杀服务(笔记+优化思路版)

本文属于看黑马的redis的学习笔记&#xff0c;记录了思路和优化流程&#xff0c;精简版最终版请点击这里查看。 文章目录一、全局ID生成器1.1 理论1.1.1 全局唯一ID生成策略1.2 代码(Redis自增)二、实现优惠券秒杀下单2.1 SQL2.2 SQL对应实体类2.2.1 普通券实体类2.2.2 秒杀券实…

声纹识别之说话人验证speaker verification

目录 一、speaker verification简介 二、主流方案和模型 1、Ecapa_TDNN模型 2、WavLm 三、代码实践 1、Ecapa_TDNN方案 a、模型结构 b、loss c、数据处理 d、模型训练和评估 e、说话人验证推理 2、WavLm预训练方案 a、模型结构和loss b、数据处理 c、模型训练 …

html5支持的几种音频格式介绍

关于音频的格式 ogg音频 Ogg全称应该是OGGVobis(oggVorbis)是一种新的音频压缩格式&#xff0c;类似于MP3等的音乐格式。Ogg是完全免费、开放和没 有专利限制的。OggVorbis文件的扩展名是.OGG。Ogg文件格式可以不断地进行大小和音质的改良&#xff0c;而不影响旧有的编码器或…

合合信息扫描全能王“照片高清修复”功能上线,3秒还原老照片

穿越时光的“美颜”!合合信息智能图像处理技术让老照片“焕新”“春运”已经开始&#xff0c;团聚时刻即将到来。和亲人们一起围炉话家常&#xff0c;翻开旧日的相册&#xff0c;品读一张张泛黄的照片背后最牵动人心的情感&#xff0c;也是“年味”所在。时光会在照片上留下斑驳…

巨量引擎·2023教育Future大会:扎根内容生态,做好经营提效

求知方寸间&#xff0c;如风过千川。当知识创作成为新的潮流&#xff0c;当教育数字化迈入直播与短视频新时代&#xff0c;当图书电商红红火火&#xff0c;如何做好教育全产业链升级与创新&#xff1f;新年伊始&#xff0c;巨量引擎举办“行知.行为.行万里 2023教育Future大会”…

嵌入式实时操作系统的设计与开发(六)

中断系统结构 在RTOS中&#xff0c;中断是与具体硬件平台关联度最大的部分&#xff0c;为了实现高可移植性、可配置性&#xff0c;中断子系统依照aCoral的整体结构来设计&#xff0c;划分为HAL&#xff08;硬件抽象层&#xff09;和内核层。 在HAL层先将各种中断汇拢&#xff…

第三周周二1.10

-A 添加规则 -I 插入 -F 清空 -L 查看 -p 调整默认规则 -D 删除规则 dport : -j ACCEPT DROP REJECT LOG /var/log/messages -n 以数字的形式显示结果 -v 详细信息 -x 精确的 -line-number 行号 删除&#xff1a;指…

2023 年你应该知道的 10 个开源项目

精心策划的 2023 年 GitHub 上最有趣的开发工具和项目列表。1.NetBeansNetBeans 是一个开源的集成开发环境&#xff0c;因其支持多种编程语言和平台而受到开发人员的欢迎。动图2.OpenCVOpenCV 是一个用于图像和视频处理的开源计算机视觉库。它广泛用于对象检测、面部识别和机器…