基本上,我所做的是使用NAudio获取峰值信息。我已经制作了一组20张图片来代表情商。我做了一些代码来检查峰值,并使用计时器实时更改picturebox中的图像。虽然有时我看到视觉滞后,我认为代码是相当低效的。有比这大块ifs更有效的代码吗?
private void EQ_TIMER_Tick(object sender, EventArgs e)
{
int vol = (int)((float)(device.AudioMeterInformation.MasterPeakValue * 100));
if ((vol > 0) && (vol < 5))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ5;
}
else if ((vol > 5) && (vol < 10))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ10;
}
else if ((vol > 10) && (vol < 15))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ15;
}
else if ((vol > 15) && (vol < 20))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ20;
}
else if ((vol > 20) && (vol < 25))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ25;
}
else if ((vol > 25) && (vol < 30))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ30;
}
else if ((vol > 30) && (vol < 35))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ35;
}
else if ((vol > 35) && (vol < 40))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ40;
}
else if ((vol > 40) && (vol < 45))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ45;
}
else if ((vol > 45) && (vol < 50))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ50;
}
else if ((vol > 50) && (vol < 55))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ55;
}
else if ((vol > 55) && (vol < 60))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ60;
}
else if ((vol > 60) && (vol < 65))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ65;
}
else if ((vol > 65) && (vol < 70))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ70;
}
else if ((vol > 70) && (vol < 75))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ75;
}
else if ((vol > 75) && (vol < 80))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ80;
}
else if ((vol > 80) && (vol < 85))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ85;
}
else if ((vol > 85) && (vol < 90))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ90;
}
else if ((vol > 90) && (vol < 95))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ95;
}
else if ((vol > 95) && (vol < 100))
{
WINGS_FRAME.Image = Properties.Resources.RES_EQ100;
}
else if (vol == 0)
{
WINGS_FRAME.Image = null;
}
}发布于 2016-04-17 11:14:11
试着做这样的事情:
int vol = 38;
int imgnum = vol/5*5;
string imgname = string.Format("RES_EQ{0}", imgnum);
var image = Properties.Resources.ResourceManager.GetObject(imgname);整数除法将卷“舍入”到一个步数,然后乘以5,得到图像的实际数字。
https://stackoverflow.com/questions/36675649
复制相似问题