示例#1
0
        /// <summary>
        /// Opens a document from a jpeg file with embedded QuickRoute Jpeg Extension Data.
        /// </summary>
        /// <param name="fileName">The file name of the jpeg file.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns>A QuickRoute document if the jpeg file contains QuickRoute Jpeg Extension Data, otherwise null.</returns>
        public static Document OpenFromJpeg(string fileName, DocumentSettings settings)
        {
            var ed = QuickRouteJpegExtensionData.FromJpegFile(fileName);

            if (ed == null)
            {
                return(null);
            }
            var mapAndBorderImage = (Bitmap)Image.FromFile(fileName);

            var mapImage = new Bitmap(ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height);

            using (var g = Graphics.FromImage(mapImage))
            {
                g.DrawImage(mapAndBorderImage,
                            new Rectangle(0, 0, ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height),
                            ed.MapLocationAndSizeInPixels,
                            GraphicsUnit.Pixel);
            }
            foreach (var pi in mapAndBorderImage.PropertyItems)
            {
                mapImage.SetPropertyItem(pi);
            }

            var exif             = new ExifWorks.ExifWorks(ref mapAndBorderImage);
            var qualityByteArray = exif.GetProperty((int)ExifWorks.ExifWorks.TagNames.JPEGQuality, new byte[] { 80 });

            var encodingInfo = new JpegEncodingInfo((double)qualityByteArray[0] / 100);

            using (var ms = new MemoryStream())
            {
                mapImage.Save(ms, encodingInfo.Encoder, encodingInfo.EncoderParams);
                var document = new Document(new Map(ms), settings)
                {
                    Sessions = ed.Sessions
                };
                if (document.Sessions.Count > 0)
                {
                    document.ProjectionOrigin = document.Sessions[0].ProjectionOrigin;
                }
                document.FileName   = fileName;
                document.FileFormat = QuickRouteFileFormat.Jpeg;
                document.Initialize();
                mapAndBorderImage.Dispose();
                mapImage.Dispose();
                return(document);
            }
        }
示例#2
0
        /// <summary>
        /// Opens a document stored in the old QuickRoute XML file format. This version can't save documents in this file format.
        /// </summary>
        /// <param name="fileName">The file name of the QuickRoute 1.0 xml document.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns></returns>
        public static Document OpenFromXml(string fileName, DocumentSettings settings)
        {
            XmlTextReader reader = null;

              RouteSegment rs = new RouteSegment();
              HandleCollection handles = new HandleCollection();
              Map map;

              try
              {

            reader = new XmlTextReader(fileName);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            reader.ReadStartElement("QuickRoute");

            reader.ReadStartElement("Route");

            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
            {
              while (reader.NodeType != XmlNodeType.Element) reader.Read();
              Waypoint t = new Waypoint();
              t.Time = DateTime.Parse(reader.GetAttribute("time"));
              t.LongLat = new LongLat();
              t.LongLat.Longitude = double.Parse(reader.GetAttribute("longitude"));
              t.LongLat.Latitude = double.Parse(reader.GetAttribute("latitude"));
              t.Altitude = double.Parse(reader.GetAttribute("altitude"));
              t.HeartRate = int.Parse(reader.GetAttribute("heartRate"));
              rs.Waypoints.Add(t);
            }
            reader.ReadEndElement();

            reader.ReadStartElement("Markers");
            while (reader.Name == "Handle")
            {
              reader.Read();
              Handle h = new Handle();
              h.ParameterizedLocation = new ParameterizedLocation(0, double.Parse(reader.GetAttribute("value")));
              reader.Read();
              double x = double.Parse(reader.GetAttribute("x"));
              double y = double.Parse(reader.GetAttribute("y"));
              h.Location = new PointD(x, y);
              reader.Read();
              h.TransformationMatrix = new GeneralMatrix(3, 3);
              h.MarkerDrawer = (new ApplicationSettings()).DefaultDocumentSettings.DefaultSessionSettings.MarkerDrawers[MarkerType.Handle];
              for (int row = 0; row < 3; row++)
              {
            for (int col = 0; col < 3; col++)
            {
              reader.Read();
              h.TransformationMatrix.SetElement(row, col, double.Parse(reader.GetAttribute("value")));
            }
              }
              reader.Read();
              reader.ReadEndElement();
              reader.ReadEndElement();
              handles.Add(h);
            }
            reader.ReadEndElement();

            map = new Map(Base64StringToBitmap(reader.ReadElementContentAsString()));

              }
              catch (Exception ex)
              {
            if (reader != null) reader.Close();
            throw new Exception(ex.Message);
              }
              reader.Close();

              List<RouteSegment> routeSegments = new List<RouteSegment>();
              routeSegments.Add(rs);
              Document doc = new Document(map, new Route(routeSegments), new LapCollection(), null, settings);
              foreach (var h in handles)
              {
            doc.Sessions[0].AddHandle(h);
              }
              doc.FileFormat = QuickRouteFileFormat.Xml;
              doc.Initialize();
              UpdateDocumentToCurrentVersion(doc);
              return doc;
        }
示例#3
0
        /// <summary>
        /// Opens a document from a jpeg file with embedded QuickRoute Jpeg Extension Data.
        /// </summary>
        /// <param name="fileName">The file name of the jpeg file.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns>A QuickRoute document if the jpeg file contains QuickRoute Jpeg Extension Data, otherwise null.</returns>
        public static Document OpenFromJpeg(string fileName, DocumentSettings settings)
        {
            var ed = QuickRouteJpegExtensionData.FromJpegFile(fileName);
              if (ed == null) return null;
              var mapAndBorderImage = (Bitmap)Image.FromFile(fileName);

              var mapImage = new Bitmap(ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height);
              using(var g = Graphics.FromImage(mapImage))
              {
            g.DrawImage(mapAndBorderImage,
                    new Rectangle(0, 0, ed.MapLocationAndSizeInPixels.Width, ed.MapLocationAndSizeInPixels.Height),
                    ed.MapLocationAndSizeInPixels,
                    GraphicsUnit.Pixel);
              }
              foreach(var pi in mapAndBorderImage.PropertyItems)
              {
            mapImage.SetPropertyItem(pi);
              }

              var exif = new ExifWorks.ExifWorks(ref mapAndBorderImage);
              var qualityByteArray = exif.GetProperty((int)ExifWorks.ExifWorks.TagNames.JPEGQuality, new byte[] { 80 });

              var encodingInfo = new JpegEncodingInfo((double)qualityByteArray[0] / 100);
              using (var ms = new MemoryStream())
              {
            mapImage.Save(ms, encodingInfo.Encoder, encodingInfo.EncoderParams);
            var document = new Document(new Map(ms), settings) { Sessions = ed.Sessions };
            if (document.Sessions.Count > 0) document.ProjectionOrigin = document.Sessions[0].ProjectionOrigin;
            document.FileName = fileName;
            document.FileFormat = QuickRouteFileFormat.Jpeg;
            document.Initialize();
            mapAndBorderImage.Dispose();
            mapImage.Dispose();
            return document;
              }
        }
示例#4
0
 private void InitDocumentAndSessions()
 {
     if (type == KmlExportDocumentType.File && document == null)
       {
     document = Document.Open(fileName);
     if (document != null)
     {
       document.Initialize();
       sessions = document.Sessions;
     }
       }
 }
示例#5
0
        /// <summary>
        /// Opens a document stored in the old QuickRoute XML file format. This version can't save documents in this file format.
        /// </summary>
        /// <param name="fileName">The file name of the QuickRoute 1.0 xml document.</param>
        /// <param name="settings">The document settings to apply.</param>
        /// <returns></returns>
        public static Document OpenFromXml(string fileName, DocumentSettings settings)
        {
            XmlTextReader reader = null;

            RouteSegment     rs      = new RouteSegment();
            HandleCollection handles = new HandleCollection();
            Map map;

            try
            {
                reader = new XmlTextReader(fileName);
                reader.WhitespaceHandling = WhitespaceHandling.None;

                reader.ReadStartElement("QuickRoute");

                reader.ReadStartElement("Route");

                while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                {
                    while (reader.NodeType != XmlNodeType.Element)
                    {
                        reader.Read();
                    }
                    Waypoint t = new Waypoint();
                    t.Time              = DateTime.Parse(reader.GetAttribute("time"));
                    t.LongLat           = new LongLat();
                    t.LongLat.Longitude = double.Parse(reader.GetAttribute("longitude"));
                    t.LongLat.Latitude  = double.Parse(reader.GetAttribute("latitude"));
                    t.Altitude          = double.Parse(reader.GetAttribute("altitude"));
                    t.HeartRate         = int.Parse(reader.GetAttribute("heartRate"));
                    rs.Waypoints.Add(t);
                }
                reader.ReadEndElement();

                reader.ReadStartElement("Markers");
                while (reader.Name == "Handle")
                {
                    reader.Read();
                    Handle h = new Handle();
                    h.ParameterizedLocation = new ParameterizedLocation(0, double.Parse(reader.GetAttribute("value")));
                    reader.Read();
                    double x = double.Parse(reader.GetAttribute("x"));
                    double y = double.Parse(reader.GetAttribute("y"));
                    h.Location = new PointD(x, y);
                    reader.Read();
                    h.TransformationMatrix = new GeneralMatrix(3, 3);
                    h.MarkerDrawer         = (new ApplicationSettings()).DefaultDocumentSettings.DefaultSessionSettings.MarkerDrawers[MarkerType.Handle];
                    for (int row = 0; row < 3; row++)
                    {
                        for (int col = 0; col < 3; col++)
                        {
                            reader.Read();
                            h.TransformationMatrix.SetElement(row, col, double.Parse(reader.GetAttribute("value")));
                        }
                    }
                    reader.Read();
                    reader.ReadEndElement();
                    reader.ReadEndElement();
                    handles.Add(h);
                }
                reader.ReadEndElement();

                map = new Map(Base64StringToBitmap(reader.ReadElementContentAsString()));
            }
            catch (Exception ex)
            {
                if (reader != null)
                {
                    reader.Close();
                }
                throw new Exception(ex.Message);
            }
            reader.Close();

            List <RouteSegment> routeSegments = new List <RouteSegment>();

            routeSegments.Add(rs);
            Document doc = new Document(map, new Route(routeSegments), new LapCollection(), null, settings);

            foreach (var h in handles)
            {
                doc.Sessions[0].AddHandle(h);
            }
            doc.FileFormat = QuickRouteFileFormat.Xml;
            doc.Initialize();
            UpdateDocumentToCurrentVersion(doc);
            return(doc);
        }