歌词文件解析(二):LRC格式文件的绘制

时间:2021-03-31 20:39:50

  通过对LRC文件的解析,可以轻松实现歌词可视化.

代码实现

函数名:

paintLyrics(ByVal pBox As PictureBox, ByVal CurrentPosition As Integer, ByVal type As Boolean, Optional ByVal pLyric As LyricClass = Nothing)

参数:

pBox:用于绘制歌词的Picturebox

CurrentPosition:当前歌词的时间进度,单位为秒(Second)

type:值为True时强行绘制歌词

pLyric:可选参数,要绘制的歌词类(LyricClass)

功能:

1.歌词居中显示

2.自动匹配显示行数

3.当前歌词突出显示

  '绘制歌词
    Public Sub paintLyrics(ByVal pBox As PictureBox, ByVal CurrentPosition As Integer, ByVal type As Boolean, Optional ByVal pLyric As LyricClass = Nothing)
        Dim stringFormat As New StringFormat() With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center}
        Dim tempI, tempII, pWidth, pHeight As Integer
        Dim myfont As Font
        Dim mybrush As SolidBrush
        Dim bmp As Bitmap

             > LyricData.LyricTime(LyricData.Count -  - i) Then
                tempII = LyricData.Count -  - i
                Exit For
            End If
            tempII = -
        Next
        If Not tempII = tempI Or type = True Then
            If pLyric Is Nothing Then pLyric = Me
            tempI = tempII
            myfont = )
            mybrush = , , , ))
            pWidth = pBox.Width : pHeight = pBox.Height
            bmp = New Bitmap(pWidth, pHeight)
            Dim pg As Graphics = Graphics.FromImage(bmp)
            pg.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
             To pHeight '绘制渐变背景
                pg.DrawLine( + Math.Abs(i / (pHeight / ) - ), , , ), ), , i, pWidth, i)
            Next
             Then
                pg.DrawString(, pHeight / , stringFormat)
            Else

                     , pHeight /  - i * , stringFormat)
                     , pHeight /  + i * , stringFormat)
                Next
                myfont = )
                mybrush = , , , ))
                  , pHeight / , stringFormat)
            End If
            pBox.Image = bmp
            pg.Dispose()
        End If
    End Sub