/// <summary> /// Updates the chart with the new maxValue (saturation) on load /// </summary> private void SB_maxValue_valueChanged(object sender, EventArgs e) { if (isPressed != true && isLoaded == true) { this.Cursor = Cursors.Wait; image = null; if (MainWindow.settings.MainS.eventSize == 16) { c16.generateSonogram("archivobmp", SB_maxValue.Value); } else if (MainWindow.settings.MainS.eventSize == 32) { c32.generateSonogram("archivobmp", (int)SB_maxValue.Value); } BitmapImage _image = new BitmapImage(); _image.BeginInit(); _image.CacheOption = BitmapCacheOption.None; _image.CacheOption = BitmapCacheOption.OnLoad; _image.CreateOptions = BitmapCreateOptions.IgnoreImageCache; _image.UriSource = new Uri(@"component/../archivobmp.png", UriKind.RelativeOrAbsolute); _image.EndInit(); Img_Sonogram.Source = _image; this.Cursor = Cursors.Arrow; } }
/// <summary> /// PDF click event. Generates a PDF with the cochleogram, histogram, sonogram, disparity between cochleae and average activity of the loaded aedat file. /// </summary> private void Btn_PDF_Click(object sender, RoutedEventArgs e) { SaveFileDialog savePDFDialog = new SaveFileDialog(); savePDFDialog.Title = "Select a name and a path for the .pdf file"; savePDFDialog.Filter = "pdf files|*.pdf"; if (savePDFDialog.ShowDialog() == true) { this.Cursor = Cursors.Wait; Document doc = new Document(); PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(savePDFDialog.FileName, FileMode.Create)); doc.SetPageSize(iTextSharp.text.PageSize.A4); doc.SetMargins(50, 50, 50, 50); doc.Open(); #region Fonts iTextSharp.text.Font fTitle = FontFactory.GetFont("Arial", 30, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); iTextSharp.text.Font fHead = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); iTextSharp.text.Font fText = FontFactory.GetFont("Arial", 11, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); #endregion #region Main page iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("\n\n\n\n\nData Report for " + fileName, fTitle); title.Alignment = Element.ALIGN_CENTER; doc.Add(title); if (settings.PdfS.showDate) { iTextSharp.text.Paragraph date = new iTextSharp.text.Paragraph("\n\n" + DateTime.Now); date.Alignment = Element.ALIGN_RIGHT; doc.Add(date); } #endregion if (settings.PdfS.showCochleogram || settings.PdfS.showHistogram) { doc.SetMargins(0, 30, 50, 30); doc.NewPage(); } iTextSharp.text.Paragraph paragraph; #region Cochleogram if (settings.PdfS.showCochleogram) { paragraph = new iTextSharp.text.Paragraph(" 1. Cochleogram\n\n", fHead); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" The following charts represents the cochleogram for both cochleae.\n", fText); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" - " + settings.MainS.leftColor + " - Left Cochlea.", fText); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" - " + settings.MainS.rightColor + " - Right Cochlea.\n\n\n", fText); doc.Add(paragraph); using (MemoryStream stream = new MemoryStream()) { chart_Cochleogram.SaveImage(stream, ImageFormat.Png); iTextSharp.text.Image chartImage2 = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImage2.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f); doc.Add(chartImage2); } } #endregion #region Histogram if (settings.PdfS.showHistogram) { paragraph = new iTextSharp.text.Paragraph("\n 2. Histogram\n\n", fHead); doc.Add(paragraph); using (MemoryStream stream = new MemoryStream()) { Histogram spd = new Histogram(); spd.chart_Histogram.Width = 773; spd.chart_Histogram.Height = 350; spd.chart_Histogram.SaveImage(stream, ChartImageFormat.Png); iTextSharp.text.Image chartImage3 = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImage3.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200); doc.Add(chartImage3); } } #endregion if (settings.PdfS.showSonogram || settings.PdfS.showDiff) { doc.SetMargins(50, 30, 50, 30); doc.NewPage(); } #region Sonogram if (settings.PdfS.showSonogram) { paragraph = new iTextSharp.text.Paragraph(" 3. Sonogram\n\n", fHead); doc.Add(paragraph); using (MemoryStream stream = new MemoryStream()) { if (settings.MainS.eventSize == 16) { aedatObject16.generateSonogram("archivobmp", aedatObject16.maxValueSonogram()); } else if (settings.MainS.eventSize == 32) { aedatObject32.generateSonogram("archivobmp", aedatObject32.maxValueSonogram()); } Sonogram sd = new Sonogram(); iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Sonogram), ImageFormat.Bmp); image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200); doc.Add(image1); } } #endregion #region Disparity if (settings.PdfS.showDiff && (cochleaInfo == EnumCochleaInfo.STEREO32 || cochleaInfo == EnumCochleaInfo.STEREO64 || cochleaInfo == EnumCochleaInfo.STEREO128 || cochleaInfo == EnumCochleaInfo.STEREO256)) { paragraph = new iTextSharp.text.Paragraph("\n\n 4. Disparity between cochleae\n\n", fHead); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" Disparity between both cochleae.\n", fText); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" - Red: left cochlea predominance.", fText); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" - Green: right cochlea predominance.\n\n\n", fText); doc.Add(paragraph); using (MemoryStream stream = new MemoryStream()) { if (settings.MainS.eventSize == 16) { aedatObject16.generateDisparity("archivobmpDiff", aedatObject16.maxValueSonogram()); } else if (settings.MainS.eventSize == 32) { aedatObject32.generateDisparity("archivobmpDiff", aedatObject32.maxValueSonogram()); } Difference sd = new Difference(); iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Difference), ImageFormat.Bmp); image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200); doc.Add(image1); } } #endregion #region Average activity if (settings.PdfS.showAverage) { doc.SetMargins(0, 30, 50, 30); doc.NewPage(); paragraph = new iTextSharp.text.Paragraph("\n\n 5. Average activity of both cochleae\n\n", fHead); doc.Add(paragraph); paragraph = new iTextSharp.text.Paragraph(" Each dot represents the average of events of a certain time period (Integration Period = " + settings.ToolsS.integrationPeriod.ToString() + " us ).\n", fText); doc.Add(paragraph); using (MemoryStream stream = new MemoryStream()) { Average m = new Average(); m.chart_Average.Width = 846; m.chart_Average.Height = 322; m.chart_Average.SaveImage(stream, ChartImageFormat.Png); iTextSharp.text.Image chartImage4 = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); chartImage4.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f); doc.Add(chartImage4); } } #endregion doc.Close(); InfoWindow iw = new InfoWindow("PDF generated", "The PDF file was generated succesfully and it's available at the path you chose"); // Tell the user that the process went OK iw.ShowDialog(); this.Cursor = Cursors.Arrow; } }