如何使用vb.net 绘制出wav音频文件的波形图
操作方法
- 01
添加一个PictureBox1 As PictureBox,然后声明一个b As New Bitmap(PictureBox1.Width, PictureBox1.Height),声明一个g As Drawing.Graphics = Drawing.Graphics.FromImage(b)。再令PictureBox1.Image = b。 最后你可以对g调用Drawing.Graphics的各种绘图函数。绘图完了之后调用 PictureBox1.Invalidate() PictureBox1.Update() 强制PictureBox1重绘。 这样就可以了。 代码,你用你读得的Wave文件的点替代这里面的Points就行了。 不要再问我Wave文件怎么读,因为我也不知道。 Imports System.Math Public Class Form1 Private g As Drawing.Graphics Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) '初始化绘图对象 g = Drawing.Graphics.FromImage(PictureBox1.Image) '设置光滑模式为反锯齿 g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias '使用一个List来存储曲线上的点 Dim Points As New List(Of Point) For n As Integer = 0 To 180 Dim theta As Integer = n * 2 Points.Add(Transform(n - 90, Sin(theta / 180 * PI) * 100)) Next '用贝塞尔曲线连接来绘制曲线 g.DrawBeziers(Pens.Black, Points.ToArray) '强制更新PictureBox PictureBox1.Invalidate() PictureBox1.Update() End Sub ' ' ' <summary> 标准坐标系转换到屏幕坐标系 </summary> Public Function Transform(ByVal x As Integer, ByVal y As Integer) As Point Return New Point(x + PictureBox1.Width \ 2, -y + PictureBox1.Height \ 2) End Function End Class