H
helder227
Guest
I try to find a solution to do an wave image from a mp3 or mp4 i have find a solution to do it in mp3
i want to make a wave image like this but the code its only apply to wav files
This is the code
Public Class Form2
'Define the pic and graphics to draw with
Dim pic As New Bitmap(Me.Width, Me.height)
Dim gfx As Graphics = Graphics.FromImage(pic)
'Data storage
Dim samplez As New List(Of Short)
Dim maxamount As Short
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gfx.DrawString("CLICK HERE!", New Font("Arial", 20), Brushes.Black, 0, 0)
PictureBox1.Image = pic 'Image.FromFile("C:\Users\Media Ads Labs\Desktop\design2\48059126_582467905531198_3884738734582661120_n.jpg")
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
GC.Collect()
Dim wavefile() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
GC.Collect()
Dim memstream As New IO.MemoryStream(wavefile)
Dim binreader As New IO.BinaryReader(memstream)
Dim ChunkID As Integer = binreader.ReadInt32()
Dim filesize As Integer = binreader.ReadInt32()
Dim rifftype As Integer = binreader.ReadInt32()
Dim fmtID As Integer = binreader.ReadInt32()
Dim fmtsize As Integer = binreader.ReadInt32()
Dim fmtcode As Integer = binreader.ReadInt16()
Dim channels As Integer = binreader.ReadInt16()
Dim samplerate As Integer = binreader.ReadInt32()
Dim fmtAvgBPS As Integer = binreader.ReadInt32()
Dim fmtblockalign As Integer = binreader.ReadInt16()
Dim bitdepth As Integer = binreader.ReadInt16()
If fmtsize = 18 Then
Dim fmtextrasize As Integer = binreader.ReadInt16()
binreader.ReadBytes(fmtextrasize)
End If
Dim DataID As Integer = binreader.ReadInt32()
Dim DataSize As Integer = binreader.ReadInt32()
'Grabbing the data into 16bit words known as samples
samplez.Clear()
For i = 0 To (DataSize - 1) / 2
samplez.Add(binreader.ReadInt16())
If samplez(samplez.Count - 1) > maxamount Then 'Using this for the pic
maxamount = samplez(samplez.Count - 1)
End If
Next
DrawAudio()
End Sub
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If samplez.Count > 0 Then
DrawAudio()
End If
End Sub
Private Sub DrawAudio()
'Redefine since size changed
pic = New Bitmap(PictureBox1.Width, PictureBox1.Height)
gfx = Graphics.FromImage(pic)
'Clear picturebox
gfx.FillRectangle(Brushes.Black, 0, 0, pic.Width, pic.Height)
Dim ratio As Integer = (samplez.Count - 1) / (pic.Width - 1) 'If there are 10000 samples and 200 pixels, this would be every 50th sample is shown
Dim halfpic As Integer = (pic.Height / 2) 'Simply half the height of the picturebox
For i = 1 To pic.Width - 10 Step 2 'Steping 2 because in one go, we do 2 samples
Dim leftdata As Integer = Math.Abs(samplez(i * ratio)) 'Grabbing that N-th sample to display. Using Absolute to show them one direction
Dim leftpercent As Single = leftdata / (maxamount * 2) 'This breaks it down to something like 0.0 to 1.0. Multiplying by 2 to make it half.
Dim leftpicheight As Integer = leftpercent * pic.Height 'So when the percent is tied to the height, its only a percent of the height
gfx.DrawLine(Pens.LimeGreen, i, halfpic, i, leftpicheight + halfpic) 'Draw dat! The half pic puts it in the center
Dim rightdata As Integer = Math.Abs(samplez((i + 1) * ratio)) 'Same thing except we're grabbing i + 1 because we'd skip it because of the 'step 2' on the for statement
Dim rightpercent As Single = -rightdata / (maxamount * 2) 'put a negative infront of data so it goes down.
Dim rightpicheight As Integer = rightpercent * pic.Height
gfx.DrawLine(Pens.Blue, i, halfpic, i, rightpicheight + halfpic)
Next
PictureBox1.Image = pic
End Sub
End Class
Continue reading...
i want to make a wave image like this but the code its only apply to wav files
This is the code
Public Class Form2
'Define the pic and graphics to draw with
Dim pic As New Bitmap(Me.Width, Me.height)
Dim gfx As Graphics = Graphics.FromImage(pic)
'Data storage
Dim samplez As New List(Of Short)
Dim maxamount As Short
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gfx.DrawString("CLICK HERE!", New Font("Arial", 20), Brushes.Black, 0, 0)
PictureBox1.Image = pic 'Image.FromFile("C:\Users\Media Ads Labs\Desktop\design2\48059126_582467905531198_3884738734582661120_n.jpg")
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
GC.Collect()
Dim wavefile() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
GC.Collect()
Dim memstream As New IO.MemoryStream(wavefile)
Dim binreader As New IO.BinaryReader(memstream)
Dim ChunkID As Integer = binreader.ReadInt32()
Dim filesize As Integer = binreader.ReadInt32()
Dim rifftype As Integer = binreader.ReadInt32()
Dim fmtID As Integer = binreader.ReadInt32()
Dim fmtsize As Integer = binreader.ReadInt32()
Dim fmtcode As Integer = binreader.ReadInt16()
Dim channels As Integer = binreader.ReadInt16()
Dim samplerate As Integer = binreader.ReadInt32()
Dim fmtAvgBPS As Integer = binreader.ReadInt32()
Dim fmtblockalign As Integer = binreader.ReadInt16()
Dim bitdepth As Integer = binreader.ReadInt16()
If fmtsize = 18 Then
Dim fmtextrasize As Integer = binreader.ReadInt16()
binreader.ReadBytes(fmtextrasize)
End If
Dim DataID As Integer = binreader.ReadInt32()
Dim DataSize As Integer = binreader.ReadInt32()
'Grabbing the data into 16bit words known as samples
samplez.Clear()
For i = 0 To (DataSize - 1) / 2
samplez.Add(binreader.ReadInt16())
If samplez(samplez.Count - 1) > maxamount Then 'Using this for the pic
maxamount = samplez(samplez.Count - 1)
End If
Next
DrawAudio()
End Sub
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If samplez.Count > 0 Then
DrawAudio()
End If
End Sub
Private Sub DrawAudio()
'Redefine since size changed
pic = New Bitmap(PictureBox1.Width, PictureBox1.Height)
gfx = Graphics.FromImage(pic)
'Clear picturebox
gfx.FillRectangle(Brushes.Black, 0, 0, pic.Width, pic.Height)
Dim ratio As Integer = (samplez.Count - 1) / (pic.Width - 1) 'If there are 10000 samples and 200 pixels, this would be every 50th sample is shown
Dim halfpic As Integer = (pic.Height / 2) 'Simply half the height of the picturebox
For i = 1 To pic.Width - 10 Step 2 'Steping 2 because in one go, we do 2 samples
Dim leftdata As Integer = Math.Abs(samplez(i * ratio)) 'Grabbing that N-th sample to display. Using Absolute to show them one direction
Dim leftpercent As Single = leftdata / (maxamount * 2) 'This breaks it down to something like 0.0 to 1.0. Multiplying by 2 to make it half.
Dim leftpicheight As Integer = leftpercent * pic.Height 'So when the percent is tied to the height, its only a percent of the height
gfx.DrawLine(Pens.LimeGreen, i, halfpic, i, leftpicheight + halfpic) 'Draw dat! The half pic puts it in the center
Dim rightdata As Integer = Math.Abs(samplez((i + 1) * ratio)) 'Same thing except we're grabbing i + 1 because we'd skip it because of the 'step 2' on the for statement
Dim rightpercent As Single = -rightdata / (maxamount * 2) 'put a negative infront of data so it goes down.
Dim rightpicheight As Integer = rightpercent * pic.Height
gfx.DrawLine(Pens.Blue, i, halfpic, i, rightpicheight + halfpic)
Next
PictureBox1.Image = pic
End Sub
End Class
Continue reading...