public void Lock() { if (!isLocked) { bmpData = Bmp.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, Bmp.PixelFormat); } isLocked = true; }
public void Render(Graphics g, Rectangle area, long start, long count, long step) { if (Bmp == null) { return; } var spectrums = Data.Iterate(start, area.Width, step); var x = 0; const int pixelSize = 3; var bmd = Bmp.LockBits(new Rectangle(0, 0, Bmp.Width, Bmp.Height), ImageLockMode.ReadWrite, Bmp.PixelFormat); unsafe { foreach (var spectrum in spectrums) { var skip = spectrum.Length / (double)area.Height / 2; if (spectrum.Length > 0) { var row = (byte *)bmd.Scan0; var yy = area.Height - 1; for (var y = 0; y < bmd.Height - 1; y++) { var idx = (int)(yy-- *skip); if (idx < 0) { idx = 0; } if (idx >= spectrum.Length) { idx = spectrum.Length - 1; } var value = (int)(255 * spectrum[idx]); if (value > 255) { value = 255; } if (value < 0) { value = 0; } var pixelColor = Palette[value]; row[x + 0] = pixelColor.B; row[x + 1] = pixelColor.G; row[x + 2] = pixelColor.R; row += bmd.Stride; } } x += pixelSize; } } Bmp.UnlockBits(bmd); g.DrawImage(Bmp, area.Location); }