protected override void RenderImage(string musicXml, string fileName, string outputPath, ScoreRenderingModes mode, string pathToCompare) { var newFileName = fileName.Replace(".xml", $"_{mode}.png"); var noteViewer = new NoteViewer(); noteViewer.RenderingMode = mode; noteViewer.IsOccupyingSpace = true; noteViewer.XmlSource = musicXml; //Ustalamy orientacyjne wymiary i mierzymy kontrolkę, żeby uaktualniło się ActualWidth: noteViewer.Measure(new System.Windows.Size(double.MaxValue, double.MaxValue)); noteViewer.Arrange(new Rect(0, 0, double.MaxValue, double.MaxValue)); int outputDpi = 200; double newWidthX = (outputDpi * noteViewer.DesiredSize.Width) / 96; double newHeightY = (outputDpi * noteViewer.DesiredSize.Height) / 96; RenderTargetBitmap bmp = new RenderTargetBitmap((int)newWidthX, (int)newHeightY, outputDpi, outputDpi, PixelFormats.Default); noteViewer.InvalidateVisual(); DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { drawingContext.DrawRectangle(System.Windows.Media.Brushes.White, null, new Rect(0, 0, newWidthX, newHeightY)); if (!string.IsNullOrWhiteSpace(pathToCompare)) { var oldVersion = Path.Combine(pathToCompare, newFileName); var tintedVersion = TintImage(oldVersion); var tintedPath = Path.Combine(outputPath, Path.GetFileName(oldVersion).Replace(".png", "_TINT.png")); tintedVersion.Save(tintedPath); tintedVersion.Dispose(); BitmapImage resizedTintedImage = new BitmapImage(); resizedTintedImage.BeginInit(); resizedTintedImage.UriSource = new Uri(tintedPath); resizedTintedImage.EndInit(); drawingContext.DrawImage(resizedTintedImage, new Rect(0, 0, resizedTintedImage.Width / (outputDpi / resizedTintedImage.DpiX), resizedTintedImage.Height / (outputDpi / resizedTintedImage.DpiY))); } } bmp.Render(drawingVisual); bmp.Render(noteViewer); //Konwertujemy na obrazek i zapisujemy do pola ImageData: BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); var filePath = Path.Combine(outputPath, newFileName); using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { encoder.Save(fs); fs.Flush(); fs.Close(); } }
void NoteUpdater_Tick(object sender, EventArgs e) { Dispatcher.BeginInvoke(() => { instrumentBoard1.ReleaseAll(); NoteViewer.Update(); if (Processor.MusicNotation.Samples.Count == 0) { return; } Sample Note = Processor.MusicNotation. Samples[Processor.MusicNotation.Samples.Count - 1]; if (!(Note == null || Note.ID == int.MinValue || Note.ID == int.MaxValue)) { instrumentBoard1.Press(Note.ID); } }); }
private void btnSaveLoad_Click(object sender, RoutedEventArgs e) { if (rbRecognition != null) { if (NoteUpdater.IsEnabled) { var Dialog = new ModalDialog(); Dialog.tbMessage.Text = "Остановите запись."; Dialog.Title = " "; Dialog.Show(); } else if (NoteViewer.Mode == MusicNotationMode.Create) { dialog = new SaveFileDialog(); dialog.DefaultExt = ".mid"; dialog.Filter = "Midi Files|*.mid"; bool?dialogResult = dialog.ShowDialog(); if ((bool)dialogResult) { var buffer = NoteViewer.SaveToMidi(); //var buffer = (Processor.MusicNotation as MusicNotationCreator).SaveToMidi(); var File = dialog.OpenFile(); File.Write(buffer, 0, buffer.Length); File.Close(); } } else { OpenFileDialog OpenFileDialog = new OpenFileDialog(); if (OpenFileDialog.ShowDialog() == true) { NoteViewer.LoadFromXmlStream(OpenFileDialog.File.OpenRead()); } } } }
public DispatcherCanvasScoreRenderer(Canvas canvas, NoteViewer control, WpfScoreRendererSettings rendererSettings) : base(canvas, rendererSettings) { this.control = control; }
public DispatcherCanvasScoreRenderer(Canvas canvas, NoteViewer control) : base(canvas) { this.control = control; }
private void viewProfileToolStripMenuItem_Click(object sender, EventArgs e) { NoteViewer nv = new NoteViewer(); nv.ID = dataGridView1.CurrentRow.Cells[0].Value.ToString(); nv.Viewer = "profile"; nv.ShowDialog(); }