|
| 1 | +using Spectrogram.Settings; |
| 2 | +using System.Drawing; |
| 3 | + |
| 4 | +namespace Spectrogram |
| 5 | +{ |
| 6 | + public class Annotations |
| 7 | + { |
| 8 | + public static void drawTicks(Bitmap bmp, FftSettings fftSettings, DisplaySettings displaySettings) |
| 9 | + { |
| 10 | + Graphics gfx = Graphics.FromImage(bmp); |
| 11 | + |
| 12 | + double frequency = fftSettings.FrequencyFromIndex(displaySettings.pixelLower); |
| 13 | + double deltaFreq = 500; |
| 14 | + frequency += deltaFreq; |
| 15 | + while (frequency < fftSettings.FrequencyFromIndex(displaySettings.pixelUpper)) |
| 16 | + { |
| 17 | + int yPosition = bmp.Height - (fftSettings.IndexFromFrequency(frequency) - displaySettings.pixelLower); |
| 18 | + Point p1 = new Point(bmp.Width - displaySettings.tickSize, yPosition); |
| 19 | + Point p2 = new Point(bmp.Width, yPosition); |
| 20 | + DrawLineWithShadow(gfx, p1, p2); |
| 21 | + DrawTextWithShadow(gfx, frequency.ToString(), p1, displaySettings.tickFont, displaySettings.sfTicksRight); |
| 22 | + frequency += deltaFreq; |
| 23 | + } |
| 24 | + |
| 25 | + double xPx = 0; |
| 26 | + while (xPx < bmp.Width) |
| 27 | + { |
| 28 | + xPx += fftSettings.segmentsPerSecond; |
| 29 | + Point p1 = new Point((int)xPx, bmp.Height); |
| 30 | + Point p2 = new Point((int)xPx, bmp.Height - displaySettings.tickSize); |
| 31 | + DrawLineWithShadow(gfx, p1, p2); |
| 32 | + //DrawTextWithShadow(gfx, xPx.ToString(), p2, displaySettings.tickFont, displaySettings.sfTicksLower); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + static void DrawTextWithShadow(Graphics gfx, string s, Point pt, Font fnt, StringFormat sf) |
| 37 | + { |
| 38 | + for (int dX = -1; dX < 2; dX++) |
| 39 | + for (int dY = -1; dY < 2; dY++) |
| 40 | + gfx.DrawString(s, fnt, Brushes.Black, pt.X + dX, pt.Y + dY, sf); |
| 41 | + |
| 42 | + gfx.DrawString(s, fnt, Brushes.White, pt, sf); |
| 43 | + } |
| 44 | + |
| 45 | + static void DrawLineWithShadow(Graphics gfx, Point p1, Point p2) |
| 46 | + { |
| 47 | + Pen penShadow = new Pen(Brushes.Black, 3); |
| 48 | + Pen penTick = new Pen(Brushes.White, 1); |
| 49 | + penShadow.EndCap = System.Drawing.Drawing2D.LineCap.Round; |
| 50 | + penTick.EndCap = System.Drawing.Drawing2D.LineCap.Round; |
| 51 | + gfx.DrawLine(penShadow, p1, p2); |
| 52 | + gfx.DrawLine(penTick, p1, p2); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments