Пример #1
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);
        }
Пример #2
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
        }