Пример #1
0
        private void ExportImage()
        {
            using (var sfd = new SaveFileDialog
                         {
                           Title = Strings.ExportImageTitle,
                           Filter = (Strings.FileFilter_JpegFiles + "|" +
                                     Strings.FileFilter_PngFiles + "|" +
                                     Strings.FileFilter_TiffFiles),
                           FileName =
                             (canvas.Document != null && canvas.Document.FileName != null
                                ? Path.GetFileNameWithoutExtension(canvas.Document.FileName)
                                : Path.GetFileNameWithoutExtension(untitledDocumentFileNameProposal)),
                           FilterIndex = 1,
                           AddExtension = true,
                           OverwritePrompt = true
                         })
              {
            if (ApplicationSettings.InitialFolders.ContainsKey(ApplicationSettings.FileDialogType.ExportFile))
            {
              sfd.InitialDirectory = ApplicationSettings.InitialFolders[ApplicationSettings.FileDialogType.ExportFile];
            }

            if (sfd.ShowDialog() == DialogResult.OK)
            {
              try
              {
            // TODO: change to saved PercentualImageSize and Quality when dialog is working
            IMapImageFileExporterDialog selector = null;
            switch (sfd.FilterIndex)
            {
              case 1: // jpeg
                selector = new JpegPropertySelector
                             {
                               SizeCalculator = canvas.Document.CalculateImageForExportSize,
                               PercentualImageSize = 1,
                               //ApplicationSettings.ExportImagePercentualImageSize,
                               Quality = 0.8 //ApplicationSettings.ExportImageQuality,
                             };
                break;

              case 2: // png
                selector = new PngPropertySelector
                             {
                               SizeCalculator = canvas.Document.CalculateImageForExportSize,
                               PercentualImageSize = 1,
                               //ApplicationSettings.ExportImagePercentualImageSize
                             };
                break;

              default: // tiff
                selector = new TiffPropertySelector
                             {
                               SizeCalculator = canvas.Document.CalculateImageForExportSize,
                               PercentualImageSize = 1,
                               //ApplicationSettings.ExportImagePercentualImageSize
                             };
                break;
            }
            if (selector.ShowPropertyDialog() == DialogResult.OK)
            {
              BeginWork();
              using (var fs = new FileStream(sfd.FileName, FileMode.Create))
              {
                var imageExporterProperties = new ImageExporterProperties()
                                                {
                                                  EncodingInfo = selector.EncodingInfo,
                                                  RouteDrawingMode = Document.RouteDrawingMode.Extended,
                                                  ColorCodingAttribute = SelectedColorCodingAttribute,
                                                  SecondaryColorCodingAttribute = SelectedSecondaryColorCodingAttribute,
                                                  PercentualSize = selector.PercentualImageSize,
                                                  ColorRangeProperties = GetCurrentColorRangeProperties()
                                                };
                var imageExporter = new ImageExporter(canvas.Document, canvas.SelectedSessions, fs)
                                      {
                                        Properties = imageExporterProperties
                                      };
                imageExporter.Export();
                fs.Close();
              }
              ApplicationSettings.ExportImagePercentualImageSize = selector.PercentualImageSize;
              if (selector is JpegPropertySelector)
                ApplicationSettings.ExportImageQuality = ((JpegPropertySelector)selector).Quality; // ugly!
              ApplicationSettings.InitialFolders[ApplicationSettings.FileDialogType.ExportImage] =
                Path.GetDirectoryName(sfd.FileName);
              EndWork();
            }
              }
              catch (Exception ex)
              {
            Util.ShowExceptionMessageBox(ex, Strings.Error_ExportImage);
              }
            }
              }
        }
Пример #2
0
        private MapInfo CreateMapInfoFromControls()
        {
            MapInfo mapInfo = new MapInfo();
              var selectedMap = map.SelectedValue as MapInfo;
              if (selectedMap != null) mapInfo.ID = selectedMap.ID;
              mapInfo.Date = date.Value.ToUniversalTime();
              var selectedCategory = category.SelectedItem as Category;
              if (selectedCategory != null) mapInfo.CategoryID = selectedCategory.ID;
              mapInfo.Name = name.Text;
              mapInfo.MapName = mapName.Text;
              mapInfo.Organiser = organiser.Text;
              mapInfo.Country = country.Text;
              mapInfo.Discipline = type.Text;
              mapInfo.RelayLeg = relayLeg.Text;
              mapInfo.ResultListUrl = resultListUrl.Text;
              mapInfo.Comment = comment.Text;
              mapInfo.MapImageFileExtension = imageFormat.Text;

              IMapImageFileExporterDialog selector = null;
              switch (imageFormat.Text)
              {
            case "jpg":
              selector = new JpegPropertySelector
              {
            SizeCalculator = document.CalculateImageForExportSize
              };
              break;
            case "png":
            default:
              selector = new PngPropertySelector
              {
            SizeCalculator = document.CalculateImageForExportSize
              };
              break;
            //case "tiff":
            //  selector = new TiffPropertySelector
            //  {
            //    SizeCalculator = document.CalculateImageForExportSize
            //  };

            //  break;

              }

              if (selector.ShowPropertyDialog() == DialogResult.OK)
              {
            Application.DoEvents();

            // map image
            using (var ms = new MemoryStream())
            {
              var imageExporterProperties = new ImageExporterProperties()
              {
            EncodingInfo = selector.EncodingInfo,
            RouteDrawingMode = Document.RouteDrawingMode.Extended,
            ColorCodingAttribute = colorCodingAttribute,
            SecondaryColorCodingAttribute = secondaryColorCodingAttribute,
            PercentualSize = selector.PercentualImageSize,
            ColorRangeProperties = colorRangeProperties
              };
              var imageExporter = new ImageExporter(document, document.Sessions, ms)
              {
            Properties = imageExporterProperties
              };
              imageExporter.Export();
              mapInfo.MapImageData = ms.ToArray();
            }

            // blank map image
            using (var ms = new MemoryStream())
            {
              var imageExporterProperties = new ImageExporterProperties()
              {
            EncodingInfo = selector.EncodingInfo,
            RouteDrawingMode = Document.RouteDrawingMode.None,
            PercentualSize = selector.PercentualImageSize
              };
              var blankImageExporter = new ImageExporter(document, document.Sessions, ms)
              {
            Properties = imageExporterProperties
              };
              blankImageExporter.Export();
              mapInfo.BlankMapImageData = ms.ToArray();
            }
            return mapInfo;
              }
              return null;
        }