⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waverender.vb

📁 这是一个用vb.net编写的扫描条形码程序
💻 VB
📖 第 1 页 / 共 3 页
字号:
    Private Sub vbnetWaveRender_Resize(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs) Handles MyBase.Resize
        'SetScroll()
        renderWave()
    End Sub

    'Paint Graphics
    Protected Sub Main_Paint(ByVal sender As Object, ByVal pe As System.Windows.Forms.PaintEventArgs) Handles mainpanel.Paint

        If m_GraphicInfoReady Then
            Dim grfGraphics As Graphics
            grfGraphics = pe.Graphics
            grfGraphics.DrawLine(PaintData.m_oCSD_PEN, PaintData.m_oCSD_LX, PaintData.m_oCSD_LY, PaintData.m_oCSD_SX, PaintData.m_oCSD_SY)
            grfGraphics.DrawLine(PaintData.m_oCHADT_PEN, PaintData.m_oCHADT_LX, PaintData.m_oCHADT_LY, PaintData.m_oCHADT_SX, PaintData.m_oCHADT_SY)
            grfGraphics.DrawLine(PaintData.m_oCHADB_PEN, PaintData.m_oCHADB_LX, PaintData.m_oCHADB_LY, PaintData.m_oCHADB_SX, PaintData.m_oCHADB_SY)
            grfGraphics.DrawLine(PaintData.m_oCMDTT_pen, PaintData.m_oCMDTT_LX, PaintData.m_oCMDTT_LY, PaintData.m_oCMDTT_SX, PaintData.m_oCMDTT_SY)
            grfGraphics.DrawLine(PaintData.m_oCMDTB_pen, PaintData.m_oCMDTB_LX, PaintData.m_oCMDTB_LY, PaintData.m_oCMDTB_SX, PaintData.m_oCMDTB_SY)
            grfGraphics.DrawLine(PaintData.m_oCMDBT_pen, PaintData.m_oCMDBT_LX, PaintData.m_oCMDBT_LY, PaintData.m_oCMDBT_SX, PaintData.m_oCMDBT_SY)
            grfGraphics.DrawLine(PaintData.m_oCMDBB_pen, PaintData.m_oCMDBB_LX, PaintData.m_oCMDBB_LY, PaintData.m_oCMDBB_SX, PaintData.m_oCMDBB_SY)

            If m_FileOpen Then
                If m_bUseThread Then
                    If m_ThreadDone = False Then

                        'MessageBox.Show("Running Render")
                    Else
                        If m_ThreadResultOk = True Then
                            If Not hozScroll.Visible Then
                                grfGraphics.FillRectangle(PaintData.m_WAVENDCoverBrh, PaintData.m_WAVENDCoverRec)
                            End If
                            grfGraphics.DrawPath(PaintData.m_AudioPen, PaintData.m_AudioPathL)
                            grfGraphics.DrawPath(PaintData.m_AudioPen, PaintData.m_AudioPathR)
                        Else
                            MessageBox.Show("Thread Error")
                        End If
                    End If
                Else
                    If Not hozScroll.Visible Then
                        grfGraphics.FillRectangle(PaintData.m_WAVENDCoverBrh, PaintData.m_WAVENDCoverRec)
                    End If
                    grfGraphics.DrawPath(PaintData.m_AudioPen, PaintData.m_AudioPathL)
                    grfGraphics.DrawPath(PaintData.m_AudioPen, PaintData.m_AudioPathR)
                End If
            End If

            grfGraphics.Dispose()
        End If
    End Sub

    'WaveRender
    Private Sub renderWave()
        Dim lx As Integer
        Dim ly As Integer
        Dim lMidy As Integer
        Dim lEnd As Integer
        Dim lAbsSizeY As Integer
        Dim lLastX As Integer
        Dim lLastLeftY As Integer
        Dim lLastRightY As Integer
        Dim lMax As Integer
        Dim lWavEnd As Integer

        Dim iSample As Integer

        Dim bComplete As Boolean
        Dim bRectangles As Boolean

        Dim iWavL() As Short
        Dim iWavR() As Short
        Dim iwav() As Short

        bRectangles = (m_lPixelStep >= 8)

        lx = 0
        lEnd = MyBase.ClientRectangle.Width + m_lPixelStep
        lMidy = (MyBase.ClientRectangle.Height \ 2) - 10
        lAbsSizeY = lMidy / 2

        PaintData.m_oCSD_LX = 0
        PaintData.m_oCSD_LY = lMidy
        PaintData.m_oCSD_SX = lEnd
        PaintData.m_oCSD_SY = lMidy
        PaintData.m_oCSD_PEN = New Pen(m_oColorStereoDivider)
        PaintData.m_oCSD_PEN.Width = m_oStereoDividerLineThickNess
        PaintData.m_oCSD_PEN.DashStyle = m_oStereoDividerLineStyle

        PaintData.m_oCHADT_LX = 0
        PaintData.m_oCHADT_LY = lAbsSizeY
        PaintData.m_oCHADT_SX = lEnd
        PaintData.m_oCHADT_SY = lAbsSizeY
        PaintData.m_oCHADT_PEN = New Pen(m_oColorHalfAmplitudeDivider)
        PaintData.m_oCHADT_PEN.Width = m_oHalfAmplitudeDividerLineThickNess
        PaintData.m_oCHADT_PEN.DashStyle = m_oHalfAmplitudeDividerLineStyle


        PaintData.m_oCHADB_LX = 0
        PaintData.m_oCHADB_LY = lMidy + lAbsSizeY
        PaintData.m_oCHADB_SX = lEnd
        PaintData.m_oCHADB_SY = lMidy + lAbsSizeY
        PaintData.m_oCHADB_PEN = New Pen(m_oColorHalfAmplitudeDivider)
        PaintData.m_oCHADB_PEN.Width = m_oHalfAmplitudeDividerLineThickNess
        PaintData.m_oCHADB_PEN.DashStyle = m_oHalfAmplitudeDividerLineStyle

        PaintData.m_oCMDTT_LX = 0
        PaintData.m_oCMDTT_LY = lAbsSizeY \ 2
        PaintData.m_oCMDTT_SX = lEnd
        PaintData.m_oCMDTT_SY = lAbsSizeY \ 2
        PaintData.m_oCMDTT_pen = New Pen(m_oColorMidDivider)
        PaintData.m_oCMDTT_pen.Width = m_oMidDividerLineThickNess
        PaintData.m_oCMDTT_pen.DashStyle = m_oMidDividerLineStyle

        PaintData.m_oCMDTB_LX = 0
        PaintData.m_oCMDTB_LY = (3 * lAbsSizeY) \ 2
        PaintData.m_oCMDTB_SX = lEnd
        PaintData.m_oCMDTB_SY = (3 * lAbsSizeY) \ 2
        PaintData.m_oCMDTB_pen = New Pen(m_oColorMidDivider)
        PaintData.m_oCMDTB_pen.Width = m_oMidDividerLineThickNess
        PaintData.m_oCMDTB_pen.DashStyle = m_oMidDividerLineStyle

        PaintData.m_oCMDBT_LX = 0
        PaintData.m_oCMDBT_LY = lMidy + lAbsSizeY \ 2
        PaintData.m_oCMDBT_SX = lEnd
        PaintData.m_oCMDBT_SY = lMidy + lAbsSizeY \ 2
        PaintData.m_oCMDBT_pen = New Pen(m_oColorMidDivider)
        PaintData.m_oCMDBT_pen.Width = m_oMidDividerLineThickNess
        PaintData.m_oCMDBT_pen.DashStyle = m_oMidDividerLineStyle

        PaintData.m_oCMDBB_LX = 0
        PaintData.m_oCMDBB_LY = lMidy + (3 * lAbsSizeY) \ 2
        PaintData.m_oCMDBB_SX = lEnd
        PaintData.m_oCMDBB_SY = lMidy + (3 * lAbsSizeY) \ 2
        PaintData.m_oCMDBB_pen = New Pen(m_oColorMidDivider)
        PaintData.m_oCMDBB_pen.Width = m_oMidDividerLineThickNess
        PaintData.m_oCMDBB_pen.DashStyle = m_oMidDividerLineStyle

        If m_FileOpen Then

            If Not hozScroll.Visible Then
                lWavEnd = m_cWAVRead.AudioLength \ m_lSamplePerPixelStep
                PaintData.m_WAVENDCoverRec.X = lWavEnd
                PaintData.m_WAVENDCoverRec.Y = 0
                PaintData.m_WAVENDCoverRec.Width = MyBase.ClientRectangle.Width
                PaintData.m_WAVENDCoverRec.Height = MyBase.ClientRectangle.Height
                PaintData.m_WAVENDCoverBrh = New SolidBrush(m_oNoWaveBackColor)
            End If

            If (m_bSetting) Or (m_cWAVRead.AudioLength = 0) Then
                GoTo PaintCmd
            End If

            If m_lZoom <= 1 Then
                m_cWAVRead.SeekAbsolute(hozScroll.Value)
            Else
                m_cWAVRead.SeekAbsolute(hozScroll.Value * m_lSamplePerPixelStep)
            End If

            lLastX = lx
            lLastLeftY = lAbsSizeY
            lLastRightY = lMidy + lAbsSizeY
            PaintData.m_AudioPathL = New Drawing2D.GraphicsPath
            PaintData.m_AudioPathL.StartFigure()
            PaintData.m_AudioPathR = New Drawing2D.GraphicsPath
            PaintData.m_AudioPathR.StartFigure()
            PaintData.m_AudioPen = New Pen(m_oWaveForeColor)

            bComplete = False

            If m_ThreadDone = False Then
                Exit Sub
            End If

            If m_bUseThread Then
                RaiseEvent RenderStarted()
                m_ThreadDone = False
                m_ThreadResultOk = False
                WaveInfo_handler.BeginInvoke(lLastX, lLastLeftY, lLastRightY, lx, ly, lEnd, lAbsSizeY, bRectangles, lMidy, WaveInfo_callback, Nothing)
            Else
                RaiseEvent RenderStarted()
                Dim Result As WaveData = WaveInfo(lLastX, lLastLeftY, lLastRightY, lx, ly, lEnd, lAbsSizeY, bRectangles, lMidy)
                PaintData.m_AudioPathL = Result.m_AudioPathL
                PaintData.m_AudioPathR = Result.m_AudioPathR
                RaiseEvent RenderFinished()
            End If
        End If

PaintCmd:
        m_GraphicInfoReady = True
        mainpanel.Invalidate()
    End Sub

    'Threading Functions
    'Wave information function
    Private Function WaveInfo(ByVal lLastx As Integer, ByVal lLastLeftY As Integer, ByVal lLastRightY As Integer, _
    ByVal lx As Integer, ByVal ly As Integer, ByVal lEnd As Integer, ByVal lAbsSizeY As Integer, _
    ByVal bRectangles As Boolean, ByVal lMidy As Integer) As WaveData

        Dim iWavL() As Short
        Dim iWavR() As Short
        Dim iwav() As Short
        Dim Output As WaveData
        Dim bComplete As Boolean
        Dim iSample As Integer
        Dim bFirstLoop As Boolean = True

        Output.m_AudioPathL = New Drawing2D.GraphicsPath
        Output.m_AudioPathR = New Drawing2D.GraphicsPath

        Do While ((Not bComplete) And (lx < lEnd))
            bComplete = Not m_cWAVRead.Read()
            ReDim iWavL(m_cWAVRead.ReadbufferSize - 1)
            ReDim iWavR(m_cWAVRead.ReadbufferSize - 1)
            ReDim iwav((m_cWAVRead.ReadbufferSize * 2) - 1)

            Marshal.Copy(m_cWAVRead.ReadBufferPtr, iwav, 0, (m_cWAVRead.ReadbufferSize * 2))
            Dim j As Integer = 0
            For i As Integer = 0 To UBound(iwav)
                iWavL(j) = iwav(i)
                iWavR(j) = iwav(i + 1)
                j = j + 1
                i = i + 1
            Next
            For iSample = 0 To m_cWAVRead.ReadSize - 1 Step m_lSampleStep
                ly = lAbsSizeY + (iWavL(iSample) * lAbsSizeY) / &H8000
                If bFirstLoop = False Then
                    Output.m_AudioPathL.AddLine(lLastx, lLastLeftY, lx, ly)
                End If
                If bRectangles Then
                    Dim recttemp As Drawing.Rectangle
                    recttemp.Height = 5
                    recttemp.Width = 5
                    recttemp.X = lx - 2
                    recttemp.Y = ly - 2
                    If bFirstLoop = False Then
                        Output.m_AudioPathL.AddRectangle(recttemp)
                    End If
                End If
                lLastLeftY = ly
                ly = lMidy + lAbsSizeY + (iWavR(iSample) * lAbsSizeY) / &H8000
                If bFirstLoop = False Then
                    Output.m_AudioPathR.AddLine(lLastx, lLastRightY, lx, ly)
                End If
                If bRectangles Then
                    Dim recttemp As Drawing.Rectangle
                    recttemp.Height = 5
                    recttemp.Width = 5
                    recttemp.X = lx - 2
                    recttemp.Y = ly - 2
                    If bFirstLoop = False Then
                        Output.m_AudioPathR.AddRectangle(recttemp)
                    End If
                End If
                lLastRightY = ly
                lLastx = lx
                If (iSample Mod m_lSamplePerPixelStep) = 0 Then
                    lx = lx + m_lPixelStep
                End If
                If lx >= lEnd Then
                    Exit For
                End If
                bFirstLoop = False
            Next
        Loop
        ReDim iWavL(1)
        ReDim iWavR(1)
        ReDim iwav(1)
        Return Output
    End Function
    'Thread CallBack for waveinfo function
    Private Sub GetWaveInfo_callback(ByVal ar As IAsyncResult)
        Try
            Dim result As WaveData
            result = WaveInfo_handler.EndInvoke(ar)
            UpdateUI_Worker("Task Complete", result)
        Catch ex As Exception
            Dim msg As String
            msg = "Error: " & ex.Message
            UpdateUI_Worker(msg, Nothing)
        End Try

    End Sub
    'Thread side update sub
    Private Sub UpdateUI_Worker(ByVal StatusMsg As String, ByVal result As WaveData)
        If Me.InvokeRequired Then
            Dim handler As New UpdateUIHandler(AddressOf UpdateUI_Local)
            Dim args() As Object = {StatusMsg, result}
            Me.BeginInvoke(handler, args)
        Else
            UpdateUI_Local(StatusMsg, result)
        End If
    End Sub
    'Main program update sub
    Private Sub UpdateUI_Local(ByVal StatusMsg As String, ByVal result As WaveData)
        If StatusMsg = "Task Complete" Then
            m_ThreadDone = True
            m_ThreadResultOk = True
            PaintData.m_AudioPathL = result.m_AudioPathL
            PaintData.m_AudioPathR = result.m_AudioPathR
            m_GraphicInfoReady = True
            mainpanel.Invalidate()
            RaiseEvent RenderFinished()
        Else
            m_ThreadDone = True
            m_ThreadResultOk = False
        End If
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -