コード例 #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
ファイル: Document.cs プロジェクト: romanbdev/quickroute-gps
        /// <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;
              }
        }