代码拉取完成,页面将自动刷新
同步操作将从 BetaYuan/Sound Visualizer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
namespace AudioLoopBack
{
public partial class WaveShow : UserControl
{
[DllImport("user32.dll")]
public static extern IntPtr GetDC(
IntPtr hwnd
);
private float[] _data_;
public float[] Data
{
set
{
_data_ = value;
this.Invalidate();
}
get
{
//if (_data_ != null)
return _data_;
}
}
private Color _BaseLineColor_;
public Color BaseLineColor
{
set
{
_BaseLineColor_ = value;
this.Invalidate();
}
get
{
//if (_data_ != null)
return _BaseLineColor_;
}
}
private Color _BackgroundColor_;
public Color BackgroundColor
{
set
{
_BackgroundColor_ = value;
genExtraTextBmp(ClientRectangle.Width,ClientRectangle.Height);
this.Invalidate();
}
get
{
//if (_data_ != null)
return _BackgroundColor_;
}
}
private Color _LineColor_;
public Color LineColor
{
set
{
_LineColor_ = value;
this.Invalidate();
}
get
{
//if (_data_ != null)
return _LineColor_;
}
}
private string _addtionaltext__ = null;
public string AddtionalText
{
set { _addtionaltext__ = value; this.Invalidate(); }
get { return _addtionaltext__; }
}
private Bitmap extraStrBmp;
private Rectangle lastRect;
public WaveShow()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint, true);
_data_ = new float[128];
for (int i = 0; i < 128; i++)
{
_data_[i] = (float)Math.Sin((double)i / 128 * 2 * Math.PI);
}
_LineColor_ = Color.FromArgb(255, 255, 153, 0);
_BaseLineColor_ = Color.DodgerBlue;
_BackgroundColor_ = Color.White;
_addtionaltext__ = "Additional Text!!";
this.Invalidate();
}
private void genExtraTextBmp(int Width,int Height)
{
extraStrBmp = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(extraStrBmp);
//Draw addtional string
Font StrFont = new Font("微软雅黑", Height / 10F, GraphicsUnit.Pixel);
SizeF StrSize = new SizeF();
StrSize = g.MeasureString(_addtionaltext__, StrFont);
extraStrBmp = new Bitmap((int)StrSize.Width, (int)StrSize.Height, PixelFormat.Format32bppArgb);
g = Graphics.FromImage(extraStrBmp);
g.Clear(Color.FromArgb(200, Color.White));
SolidBrush StrBrush = new SolidBrush(_BackgroundColor_);
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString(_addtionaltext__, StrFont, StrBrush, 0, 0);
}
private void waveshow_Paint(object sender, PaintEventArgs e)
{
BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
Graphics g = myBuffer.Graphics;
g.Clear(_BackgroundColor_);
Rectangle rect = this.ClientRectangle;
int maxBarHeight = rect.Height;
float bar_width_f = ((float)rect.Width / _data_.Length);
g.SmoothingMode = SmoothingMode.HighSpeed; //高质量
g.PixelOffsetMode = PixelOffsetMode.HighSpeed; //高像素偏移质量
PointF[] pf = new PointF[_data_.Length];
for (int i = 0; i < _data_.Length; i++)
{
pf[i].Y = ((float)maxBarHeight * (1.0F - (_data_[i] + 1.0F) / 2.0F));
pf[i].X = i * bar_width_f;
}
g.DrawLines(new Pen(_LineColor_, 2), pf);
g.DrawLine(new Pen(_BaseLineColor_, 1), new Point(0, maxBarHeight / 2), new Point(rect.Width, maxBarHeight / 2));
//Draw addtional string
if (lastRect != this.ClientRectangle)
{
lastRect = this.ClientRectangle;
genExtraTextBmp(lastRect.Width,lastRect.Height);
}
if (extraStrBmp != null)
g.DrawImage(extraStrBmp, new Point((int)(maxBarHeight / 18f), (int)(maxBarHeight / 18F)));
myBuffer.Render(e.Graphics);
g.Dispose();
myBuffer.Dispose();//释放资源
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。