Imports System.IO
Imports System.Diagnostics
Imports NAudio.Wave
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class Form1
Private waveFileReader As WaveFileReader
Private waveOutDevice As WaveOut
Private sourceImage As Bitmap
Private isDrawing As Boolean
Private lastPoint As Point
Private sourceImage1 As Bitmap
Private sourceImage2 As Bitmap
Private Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
Dim openFileDialog As New OpenFileDialog()
openFileDialog.Filter = "Video Files|*.mp4;*.avi;*.mkv;*.flv;*.wmv|All Files|*.*"
If openFileDialog.ShowDialog() = DialogResult.OK Then
txtSourcePath.Text = openFileDialog.FileName
End If
End Sub
Private Sub Button6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button6.Click
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "MP4 Video|*.mp4|AVI Video|*.avi|MPEG Video|*.mpeg|FLV Video|*.flv"
If saveFileDialog.ShowDialog() = DialogResult.OK Then
ConvertVideo(txtSourcePath.Text, saveFileDialog.FileName)
End If
End Sub
Public Sub ConvertVideo(ByVal sourcePath As String, ByVal destinationPath As String)
Dim ffmpegPath As String = "C:\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg.exe" '请修改为您实际的 FFmpeg.exe 路径
Dim processStartInfo As New ProcessStartInfo(ffmpegPath)
processStartInfo.Arguments = "-i " & Chr(34) & sourcePath & Chr(34) & " " & Chr(34) & destinationPath & Chr(34)
processStartInfo.UseShellExecute = False
processStartInfo.CreateNoWindow = True
Dim process As New Process()
process.StartInfo = processStartInfo
process.Start()
process.WaitForExit()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim openFileDialog As New OpenFileDialog()
openFileDialog.Filter = "Wave Files (*.wav)|*.wav"
If openFileDialog.ShowDialog() = DialogResult.OK Then
Try
waveFileReader = New WaveFileReader(openFileDialog.FileName)
Catch ex As Exception
MessageBox.Show("Error opening file: " & ex.Message)
Return
End Try
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If waveFileReader IsNot Nothing Then
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "Wave Files (*.wav)|*.wav|MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma" '持多种音频格式
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Try
Using newWriter As New WaveFileWriter(saveFileDialog.FileName, waveFileReader.WaveFormat)
waveFileReader.Position = 0
Dim buffer As Byte() = New Byte(waveFileReader.Length - 1) {}
waveFileReader.Read(buffer, 0, buffer.Length)
newWriter.Write(buffer, 0, buffer.Length)
End Using
Catch ex As Exception
MessageBox.Show("Error saving file: " & ex.Message)
End Try
End If
Else
MessageBox.Show("No file opened")
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If waveFileReader IsNot Nothing Then
Dim startSeconds As Double = CDbl(InputBox("请输入裁剪开始时间(秒)"))
Dim durationSeconds As Double = CDbl(InputBox("请输入裁剪持续时间(秒)"))
Dim startPosition As Integer = CInt(startSeconds * waveFileReader.WaveFormat.AverageBytesPerSecond)
Dim length As Integer = CInt(durationSeconds * waveFileReader.WaveFormat.AverageBytesPerSecond)
Dim croppedFile As Byte() = New Byte(length - 1) {}
waveFileReader.Position = startPosition
waveFileReader.Read(croppedFile, 0, length)
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Filter = "Wave Files (*.wav)|*.wav|MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma" '持多种音频格式
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Try
Using newWriter As New WaveFileWriter(saveFileDialog.FileName, waveFileReader.WaveFormat)
newWriter.Write(croppedFile, 0, length)
End Using
Catch ex As Exception
MessageBox.Show("Error saving cropped file: " & ex.Message)
End Try
End If
Else
MessageBox.Show("No file opened")
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.gif;*.bmp"
openFileDialog1.Title = "选择图片"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
sourceImage = New Bitmap(openFileDialog1.FileName)
PictureBox1.Image = sourceImage
End If
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPEG 图像|*.jpg|PNG 图像|*.png|BMP 图像|*.bmp"
saveFileDialog1.Title = "保存图片"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim bitmap As New Bitmap(sourceImage)
Select Case saveFileDialog1.FilterIndex
Case 1 'JPEG
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Jpeg)
Case 2 'PNG
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Png)
Case 3 'BMP
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Bmp)
End Select
Catch ex As Exception
MessageBox.Show("保存图片时出错: " & ex.Message)
End Try
End If
End Sub
End Class