/// <summary> /// 当色柱长度变化时,重画色柱 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ColorBarPictureBox_Resize(object sender, EventArgs e) { if (ColorBarPictureBox.Width <= 0 || ColorBarPictureBox.Height <= 0) { return; } Bitmap bp = new Bitmap(ColorBarPictureBox.Width, ColorBarPictureBox.Height, PixelFormat.Format32bppArgb); BitmapData bData = bp.LockBits(new Rectangle(0, 0, bp.Width, bp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Color[] colors = ColorBar.GetRGB(ColorbarSelect, bp.Width); unsafe { Color c; byte *p = (byte *)bData.Scan0; for (int i = 0; i < bp.Width; i++) { c = colors[bp.Width - i - 1]; for (int j = 0; j < bp.Height; j++) { int offset = i * 4 + j * bData.Stride; p[offset] = c.B; p[offset + 1] = c.G; p[offset + 2] = c.R; p[offset + 3] = (byte)255; } } } bp.UnlockBits(bData); ColorBarPictureBox.BackgroundImage = bp; }
/// <summary> /// 重绘频谱图 /// </summary> /// <param name="tmppic"></param> /// <param name="weight"></param> private void RedrawWeight(PictureBox tmppic, double[,] weight) { Bitmap bp = new Bitmap(tmppic.Width, tmppic.Height, PixelFormat.Format32bppArgb); BitmapData bData = bp.LockBits(new Rectangle(0, 0, bp.Width, bp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); short maxcolor = 255; Color[] colors = ColorBar.GetRGB(ColorbarSelect, maxcolor); unsafe { double scalewidth = (double)(weight.GetLength(0) - 1) / (bp.Width - 1); double tmpwidth = 0; double scaleheight = (double)(weight.GetLength(0) - 1) / (bp.Height - 1); double tmpheight = 0; short weight16x = -1, weight16y = -1; double u, v; byte * p = (byte *)bData.Scan0; short tmpweight; for (int i = 0; i < bp.Width; i++) { tmpheight = 0; weight16x = (short)Math.Floor(tmpwidth); u = tmpwidth - weight16x; for (int j = 0; j < bp.Height; j++) { weight16y = (short)Math.Floor(tmpheight); v = tmpheight - weight16y; tmpweight = (short)Math.Round((weight[weight16x, weight16y] * (1 - u) * (1 - v) + weight[Math.Min(weight.GetLength(0) - 1, weight16x + 1), weight16y] * u * (1 - v) + weight[weight16x, Math.Min(weight.GetLength(1) - 1, weight16y + 1)] * (1 - u) * v + weight[Math.Min(weight.GetLength(0) - 1, weight16x + 1), Math.Min(weight.GetLength(1) - 1, weight16y + 1)] * u * v) / maxweight * maxcolor); Color c = colors[tmpweight]; int offset = i * 4 + j * bData.Stride; p[offset] = c.B; p[offset + 1] = c.G; p[offset + 2] = c.R; p[offset + 3] = (byte)255; tmpheight += scaleheight; } tmpwidth += scalewidth; } } bp.UnlockBits(bData); tmppic.BackgroundImage = bp; }