📄 avwizardform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using gowk.multimedia;
using gowk.utility.IO;
namespace gowk.forms
{
/// <summary>
/// AVWizardForm 的摘要说明。
/// </summary>
public class AVWizardForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl ts;
private System.Windows.Forms.TabPage pvideo;
private System.Windows.Forms.TabPage paudio;
private System.Windows.Forms.Label label1;
private gowk.controls.GComboBox cmbvideoDevice;
private System.Windows.Forms.Button btnadvance;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Panel pnlpreview;
private gowk.controls.GComboBox cmboutput;
private gowk.controls.GComboBox cmbintput;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
gowk.multimedia.VideoCapturer vc;
gowk.multimedia.WaveIn wi;
gowk.multimedia.WaveOut wo;
WAVEFORMATEX wf;
gowk.multimedia.Mixer mixer;
gowk.multimedia.Mixer.MixerControlDetail indtl,outdtl;
private System.Windows.Forms.ProgressBar outvolume;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button btnsave;
private System.Windows.Forms.Button btncancel;
private System.Windows.Forms.ProgressBar involume;
public AVWizardForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
VideoCapturer.VideoCaptureDeviceCollection vcs=VideoCapturer.GetDevices();
foreach(VideoCaptureDevice vd in vcs)
{
this.cmbvideoDevice.Items.Add(new gowk.controls.GComboxItem(vd.Name));
}
if(vcs.Count>0)
this.cmbvideoDevice.SelectedIndex=0;
else
this.cmbvideoDevice.Text="没有找到视频输入设备";
AudioDevice.AudioDeviceCollection ads=AudioDevice.InputDevices();
foreach(AudioDevice ad in ads)
{
this.cmbintput.Items.Add(new gowk.controls.GComboxItem(ad.Name));
this.cmboutput.Items.Add(new gowk.controls.GComboxItem(ad.Name));
}
if(ads.Count>0)
{
this.cmbintput.SelectedIndex=0;
this.cmboutput.SelectedIndex=0;
}
else
{
this.cmbintput.Items.Add(new gowk.controls.GComboxItem("找不到音频输入设备"));
this.cmboutput.Items.Add(new gowk.controls.GComboxItem("找不到音频输出设备"));
}
mixer=new Mixer(this);
mixer.MixerControlChange+=new EventHandler(mixer_MixerControlChange);
this.outdtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
this.outvolume.Minimum=this.outdtl.Min;
this.outvolume.Maximum=this.outdtl.Max;
this.outvolume.Value=this.outdtl.Volume;
this.indtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
this.involume.Minimum=indtl.Min;
this.involume.Maximum=indtl.Max;
this.involume.Value=this.indtl.Volume;
this.vc=new VideoCapturer(this.pnlpreview,this.cmbvideoDevice.SelectedIndex);
this.vc.ConnectDevice();
this.vc.SetPreviewRate(66);
gowk.multimedia.BITMAPINFO h=this.vc.BITMAPINFO;
h.bmiHeader.biBitCount=24;
h.bmiHeader.biWidth=160;
h.bmiHeader.biHeight=120;
this.vc.BITMAPINFO=h;
this.vc.Preview=true;
wf=new WAVEFORMATEX();
wf.cbSize=0;
wf.nChannels=1;
wf.nSamplesPerSec=8000;
wf.wBitsPerSample=16;
wf.nBlockAlign=2;
wf.nAvgBytesPerSec=16000;
wf.wFormatTag=1;//pcm
wo=new WaveOut(this.cmboutput.SelectedIndex,wf,1600,20);
wo.WaveOutError+=new WaveErrorEventHandler(wo_WaveInError);
this.wo.Start();
wi=new WaveIn(this.cmbintput.SelectedIndex,wf,1600,20);
wi.WaveInError+=new WaveErrorEventHandler(wo_WaveInError);
wi.WaveCaptured+=new WaveBufferEventHandler(wi_WaveCaptured);
this.wi.Start();
this.Activate();
}
private void InitialAll(object o)
{
}
private void wo_WaveInError(object sender, MultimediaException e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
private void wi_WaveCaptured(object sender, WAVEHDR hdr)
{
if(this.ts.SelectedTab==this.paudio)
{
byte[] data=new byte[hdr.dwBytesRecorded];
System.Runtime.InteropServices.Marshal.Copy(hdr.lpData,data,0,data.Length);
gowk.multimedia.UT.LowPassWave(this.wf,data,0,5000);
this.wo.Write(data);
Bitmap bm=new Bitmap(this.pictureBox1.Width,this.pictureBox1.Height);
Graphics g=Graphics.FromImage(bm);
// g.Clear(Color.White);
Pen pen=new Pen(this.ForeColor);
int xi=(int)(this.pictureBox1.Width*16/data.Length),ys=(int)(this.pictureBox1.Height/2);
int h=this.pictureBox1.Height;
int x=-xi,y=ys,x2,y2;
if(xi<1)xi=1;
for(int i=0;i<data.Length;i+=16)
{
x2=x+xi;
y2=ys+(int)(System.BitConverter.ToInt16(data,i)/h);
g.DrawLine(pen,x,y,x2,y2);
x=x2;
y=y2;
}
g.Dispose();
this.pictureBox1.Image=bm;
}
}
private void SyncVolumn()
{
this.involume.Value=this.indtl.Volume;
this.outvolume.Value=this.outdtl.Volume;
}
private void mixer_MixerControlChange(object sender, EventArgs e)
{
this.SyncVolumn();
}
private void outvolume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.X<0||e.X>this.outvolume.Width)return;
int v=(int)(e.X*this.outvolume.Maximum/this.outvolume.Width);
this.outdtl.Volume=v;
this.outvolume.Value=this.outdtl.Volume;
}
private void involume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.X<0||e.X>this.involume.Width)return;
int v=(int)(e.X*this.involume.Maximum/this.involume.Width);
this.indtl.Volume=v;
this.involume.Value=this.indtl.Volume;
}
private void involume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.involume.Capture)involume_MouseUp(sender,e);
}
private void outvolume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.outvolume.Capture)outvolume_MouseUp(sender,e);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ts = new System.Windows.Forms.TabControl();
this.pvideo = new System.Windows.Forms.TabPage();
this.btnadvance = new System.Windows.Forms.Button();
this.cmbvideoDevice = new gowk.controls.GComboBox();
this.label1 = new System.Windows.Forms.Label();
this.pnlpreview = new System.Windows.Forms.Panel();
this.paudio = new System.Windows.Forms.TabPage();
this.outvolume = new System.Windows.Forms.ProgressBar();
this.involume = new System.Windows.Forms.ProgressBar();
this.cmboutput = new gowk.controls.GComboBox();
this.cmbintput = new gowk.controls.GComboBox();
this.label4 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnsave = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.btncancel = new System.Windows.Forms.Button();
this.ts.SuspendLayout();
this.pvideo.SuspendLayout();
this.paudio.SuspendLayout();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -