Esempio n. 1
0
        private void bgwShowImage_DoWork(object sender, DoWorkEventArgs e)
        {
            PointLatLng pos      = gMap.Position;
            int         progress = 0;

            OverlayPhotosWGS.Markers.Clear();
            OverlayPhotosMAR.Markers.Clear();
            foreach (KeyValuePair <Image, string> img in photos)
            {
                using (Image photo = new Bitmap(img.Value))
                {
                    pos.Lat = EXIF.GetLatitude(photo);
                    pos.Lng = EXIF.GetLongitude(photo);

                    photo.Dispose();
                }

                if (double.IsNaN(pos.Lat) || double.IsNaN(pos.Lng))
                {
                    continue;
                }

                double lat = pos.Lat, lng = pos.Lng;
                PosShift.Convert2Mars(pos.Lng, pos.Lat, out lng, out lat);

                GMarkerGoogle    marker_wgs = new GMarkerGoogle(pos, GMarkerGoogleType.green_dot);
                GMapImageToolTip tooltip_wgs = new GMapImageToolTip(marker_wgs);
                tooltip_wgs.Image      = img.Key;
                tooltip_wgs.Offset     = new Point(0, -12);
                tooltip_wgs.Font       = new Font("Segoe UI", 8);
                tooltip_wgs.Stroke     = new System.Drawing.Pen(System.Drawing.Color.LightCoral, 2);
                tooltip_wgs.Fill       = new SolidBrush(System.Drawing.Color.Snow);
                marker_wgs.ToolTip     = tooltip_wgs;
                marker_wgs.ToolTipText = Path.GetFileName(img.Value);
                marker_wgs.Tag         = pos;
                OverlayPhotosWGS.Markers.Add(marker_wgs);

                GMarkerGoogle    marker_mar = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.green_dot);
                GMapImageToolTip tooltip_mar = new GMapImageToolTip(marker_mar);
                tooltip_mar.Image      = img.Key;
                tooltip_mar.Offset     = new Point(0, -12);
                tooltip_mar.Font       = new Font("Segoe UI", 8);
                tooltip_mar.Stroke     = new System.Drawing.Pen(System.Drawing.Color.SlateBlue, 2);
                tooltip_mar.Fill       = new SolidBrush(System.Drawing.Color.Snow);
                marker_mar.ToolTip     = tooltip_mar;
                marker_mar.ToolTipText = Path.GetFileName(img.Value);
                marker_mar.Tag         = new PointLatLng(lat, lng);
                OverlayPhotosMAR.Markers.Add(marker_mar);

                progress++;
                if (bgwShowImage.IsBusy)
                {
                    bgwShowImage.ReportProgress(progress);
                }
            }
        }
Esempio n. 2
0
        private void picGeoRef_DragDrop(object sender, DragEventArgs e)
        {
            PointLatLng pos = gMap.Position;

            string[] flist = (string[])e.Data.GetData(DataFormats.FileDrop, true);
            picGeoRef.Load(flist[0]);

            pos.Lat = EXIF.GetLatitude(picGeoRef.Image, pos.Lat);
            pos.Lng = EXIF.GetLongitude(picGeoRef.Image, pos.Lng);

            double lat = pos.Lat, lng = pos.Lng;

            PosShift.Convert2Mars(pos.Lng, pos.Lat, out lng, out lat);

            OverlayRefPosWGS.Markers.Clear();
            //OverlayRefPosWGS.Markers.Add( new GMarkerGoogle( pos, GMarkerGoogleType.blue_pushpin ) );
            //OverlayRefPosWGS.Markers.Add( new GMarkerGoogle( pos, getPhotoThumb( picGeoRef.Image ) ) );
            GMarkerGoogle marker_wgs = new GMarkerGoogle(pos, GMarkerGoogleType.lightblue_dot);

            marker_wgs.ToolTip        = new GMapBaloonToolTip(marker_wgs);
            marker_wgs.ToolTip.Stroke = new System.Drawing.Pen(System.Drawing.Color.Violet);
            marker_wgs.ToolTip.Fill   = new SolidBrush(System.Drawing.Color.Snow);
            //marker.ToolTipText = "<html><body><img src=\"./P4083508.jpg\" /></body></html>";
            marker_wgs.ToolTipText = Path.GetFileName(flist[0]);
            OverlayRefPosWGS.Markers.Add(marker_wgs);

            OverlayRefPosMAR.Markers.Clear();
            //OverlayRefPosMAR.Markers.Add( new GMarkerGoogle( new PointLatLng(lat, lng), GMarkerGoogleType.blue_pushpin ) );
            //OverlayRefPosMAR.Markers.Add( new GMarkerGoogle( new PointLatLng( lat, lng ), getPhotoThumb( picGeoRef.Image ) ) );
            GMarkerGoogle marker_mar = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.orange_dot);

            marker_mar.ToolTip        = new GMapBaloonToolTip(marker_mar);
            marker_mar.ToolTip.Stroke = new System.Drawing.Pen(System.Drawing.Color.SlateBlue);
            marker_mar.ToolTip.Fill   = new SolidBrush(System.Drawing.Color.Snow);
            //markermar.ToolTipText = "<html><body><img src=\"./P4083508.jpg\" /></body></html>";
            marker_mar.ToolTipText = Path.GetFileName(flist[0]);
            OverlayRefPosMAR.Markers.Add(marker_mar);

            //gMap.Zoom = 12;

            updatePositions(OverlayRefPos, true);
        }
Esempio n. 3
0
        public void ShowImage(KeyValuePair <Image, string> img)
        {
            PointLatLng pos = gMap.Position;

            Image photo = new Bitmap(img.Value);

            pos.Lat = EXIF.GetLatitude(photo);
            pos.Lng = EXIF.GetLongitude(photo);
            photo.Dispose();

            if (double.IsNaN(pos.Lat) || double.IsNaN(pos.Lng))
            {
                return;
            }

            double lat = pos.Lat, lng = pos.Lng;

            PosShift.Convert2Mars(pos.Lng, pos.Lat, out lng, out lat);

            OverlayRefPosWGS.Markers.Clear();
            GMarkerGoogle marker_wgs = new GMarkerGoogle(pos, GMarkerGoogleType.pink_dot);

            marker_wgs.ToolTip        = new GMapBaloonToolTip(marker_wgs);
            marker_wgs.ToolTip.Stroke = new System.Drawing.Pen(System.Drawing.Color.Violet);
            marker_wgs.ToolTip.Fill   = new SolidBrush(System.Drawing.Color.Snow); //new SolidBrush(Color.WhiteSmoke);
            marker_wgs.ToolTipText    = Path.GetFileName(img.Value);
            OverlayRefPosWGS.Markers.Add(marker_wgs);

            OverlayRefPosMAR.Markers.Clear();
            GMarkerGoogle marker_mar = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.pink_dot);

            marker_mar.ToolTip        = new GMapBaloonToolTip(marker_mar);
            marker_mar.ToolTip.Stroke = new System.Drawing.Pen(System.Drawing.Color.SlateBlue);
            marker_mar.ToolTip.Fill   = new SolidBrush(System.Drawing.Color.Snow);
            marker_mar.ToolTipText    = Path.GetFileName(img.Value);
            OverlayRefPosMAR.Markers.Add(marker_mar);

            updatePositions(OverlayPhotos, true);
        }
Esempio n. 4
0
        public void SetImageGeoTag(PointLatLng pos)
        {
            //PointLatLng pos = gMap.Position;
            //return;

            OverlayPhotosWGS.Markers.Clear();
            OverlayPhotosMAR.Markers.Clear();
            foreach (KeyValuePair <Image, string> img in photos)
            {
                #region calc position
                double lat = pos.Lat, lng = pos.Lng;
                double lat_mar = lat, lng_mar = lng;
                double lat_wgs = lat, lng_wgs = lng;
                if (chkMapShift.Checked)
                {
                    PosShift.Convert2WGS(pos.Lng, pos.Lat, out lng, out lat);
                    lat_wgs = lat;
                    lng_wgs = lng;
                }
                else
                {
                    PosShift.Convert2Mars(pos.Lng, pos.Lat, out lng, out lat);
                    lat_mar = lat;
                    lng_mar = lng;
                }
                #endregion

                #region touch photo
                //Image photo = new Bitmap(img.Value);
                using (FileStream fs = new FileStream(img.Value, FileMode.Open, FileAccess.Read))
                {
                    Image photo = Image.FromStream(fs, true, true);
                    photo = EXIF.Geotag(photo, lat_wgs, lng_wgs);
                    fs.Close();

                    ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
                    System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                    EncoderParameters myEncoderParameters    = new EncoderParameters(1);
                    EncoderParameter  myEncoderParameter     = new EncoderParameter(myEncoder, 92L);
                    myEncoderParameters.Param[0] = myEncoderParameter;

                    photo.Save(img.Value, jpgEncoder, myEncoderParameters);
                    photo.Dispose();
                }

                Dictionary <string, string> properties = (Dictionary <string, string>)img.Key.Tag;
                if (properties != null)
                {
                    FileInfo fi = new FileInfo(img.Value);
                    DateTime dt = DateTime.Now;

                    if (!string.IsNullOrEmpty(properties["DateTaken"]))
                    {
                        dt = DateTime.Parse(properties["DateTaken"]);
                    }
                    else if (!string.IsNullOrEmpty(properties["DateCreated"]))
                    {
                        dt = DateTime.Parse(properties["DateCreated"]);
                    }
                    else if (!string.IsNullOrEmpty(properties["DateModified"]))
                    {
                        dt = DateTime.Parse(properties["DateModified"]);
                    }
                    else if (!string.IsNullOrEmpty(properties["DateAccessed"]))
                    {
                        dt = DateTime.Parse(properties["DateAccessed"]);
                    }
                    fi.LastAccessTimeUtc = dt.ToUniversalTime();
                    fi.LastWriteTimeUtc  = dt.ToUniversalTime();
                    fi.CreationTimeUtc   = dt.ToUniversalTime();
                }
                #endregion

                #region create new marker for moved marker
                GMarkerGoogle    marker_wgs = new GMarkerGoogle(new PointLatLng(lat_wgs, lng_wgs), GMarkerGoogleType.orange_dot);
                GMapImageToolTip tooltip_wgs = new GMapImageToolTip(marker_wgs);
                tooltip_wgs.Image      = img.Key;
                tooltip_wgs.Offset     = new Point(0, -12);
                tooltip_wgs.Font       = new Font("Segoe UI", 8);
                tooltip_wgs.Stroke     = new System.Drawing.Pen(System.Drawing.Color.SlateBlue, 2);
                tooltip_wgs.Fill       = new SolidBrush(System.Drawing.Color.Snow);
                marker_wgs.ToolTip     = tooltip_wgs;
                marker_wgs.ToolTipText = Path.GetFileName(img.Value);
                marker_wgs.Tag         = new PointLatLng(lat_wgs, lng_wgs);
                OverlayPhotosWGS.Markers.Add(marker_wgs);

                GMarkerGoogle    marker_mar = new GMarkerGoogle(new PointLatLng(lat_mar, lng_mar), GMarkerGoogleType.orange_dot);
                GMapImageToolTip tooltip_mar = new GMapImageToolTip(marker_mar);
                tooltip_mar.Image      = img.Key;
                tooltip_mar.Offset     = new Point(0, -12);
                tooltip_mar.Font       = new Font("Segoe UI", 8);
                tooltip_mar.Stroke     = new System.Drawing.Pen(System.Drawing.Color.SlateBlue, 2);
                tooltip_mar.Fill       = new SolidBrush(System.Drawing.Color.Snow);
                marker_mar.ToolTip     = tooltip_mar;
                marker_mar.ToolTipText = Path.GetFileName(img.Value);
                marker_mar.Tag         = new PointLatLng(lat_mar, lng_mar);
                OverlayPhotosMAR.Markers.Add(marker_mar);
                #endregion
                if (bgwSetGeo.IsBusy)
                {
                    bgwSetGeo.ReportProgress(OverlayPhotosMAR.Markers.Count);
                }
            }
            if (OverlayRefPos.Markers.Count > 0)
            {
                OverlayRefPos.Markers.RemoveAt(OverlayRefPos.Markers.Count - 1);
            }
            updatePositions(OverlayPhotos, true);
        }
Esempio n. 5
0
        public void SetImageGeoTag(PointLatLng pos, string image)
        {
            #region calc position for wgs & mars
            double lat = pos.Lat, lng = pos.Lng;
            double lat_mar = lat, lng_mar = lng;
            double lat_wgs = lat, lng_wgs = lng;
            if (chkMapShift.Checked)
            {
                PosShift.Convert2WGS(pos.Lng, pos.Lat, out lng, out lat);
                lat_wgs = lat;
                lng_wgs = lng;
            }
            else
            {
                PosShift.Convert2Mars(pos.Lng, pos.Lat, out lng, out lat);
                lat_mar = lat;
                lng_mar = lng;
            }
            #endregion

            #region update modified marker position
            GMapImageToolTip currentTooltip = (GMapImageToolTip)(currentMarker.ToolTip);
            foreach (GMarkerGoogle marker in OverlayPhotosWGS.Markers)
            {
                GMapImageToolTip markerTooltip = (GMapImageToolTip)(marker.ToolTip);
                if (markerTooltip.Image == currentTooltip.Image)
                {
                    marker.Position = new PointLatLng(lat_wgs, lng_wgs);
                    break;
                }
            }

            foreach (GMarkerGoogle marker in OverlayPhotosMAR.Markers)
            {
                GMapImageToolTip markerTooltip = (GMapImageToolTip)(marker.ToolTip);
                if (markerTooltip.Image == currentTooltip.Image)
                {
                    marker.Position = new PointLatLng(lat_mar, lng_mar);
                    break;
                }
            }
            #endregion

            #region Touch file datetime to DateTaken/DateOriginal
            FileInfo fi = new FileInfo(image);
            DateTime dt = DateTime.Now;

            using (FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read))
            {
                Image photo = Image.FromStream(fs, true, true);
                photo = EXIF.Geotag(photo, lat_wgs, lng_wgs);
                fs.Close();

                try
                {
                    if (photo.PropertyIdList.Contains(EXIF.PropertyTagExifDTOrig))
                    {
                        PropertyItem DTOrig = photo.GetPropertyItem(EXIF.PropertyTagExifDTOrig);

                        ASCIIEncoding enc           = new ASCIIEncoding();
                        string        dateTakenText = enc.GetString(DTOrig.Value, 0, DTOrig.Len - 1);

                        if (!string.IsNullOrEmpty(dateTakenText))
                        {
                            if (!DateTime.TryParseExact(dateTakenText, "yyyy:MM:dd HH:mm:ss", CultureInfo.CurrentCulture, DateTimeStyles.None, out dt))
                            {
                            }
                        }
                    }
                }
                catch { }

                ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                EncoderParameters myEncoderParameters    = new EncoderParameters(1);
                EncoderParameter  myEncoderParameter     = new EncoderParameter(myEncoder, 92L);
                myEncoderParameters.Param[0] = myEncoderParameter;

                photo.Save(image, jpgEncoder, myEncoderParameters);
                photo.Dispose();
            }
            fi.LastAccessTimeUtc = dt.ToUniversalTime();
            fi.LastWriteTimeUtc  = dt.ToUniversalTime();
            fi.CreationTimeUtc   = dt.ToUniversalTime();
            #endregion

            #region using media.image modify geotag



            #endregion
        }