Esempio n. 1
0
        /// <summary>
        /// Make a clone useable for a new PhotoViewerControl, like in DlgPhotoDraw
        /// </summary>
        /// <param name="prototype"></param>
        /// <returns></returns>
        public static PhotoDescr FromPhotoDescr(PhotoDescr prototype)
        {
            PhotoDescr ret = new PhotoDescr();

            ret.DTOrig         = prototype.DTOrig;
            ret.Latitude       = prototype.Latitude;
            ret.Longitude      = prototype.Longitude;
            ret.Altitude       = prototype.Altitude;
            ret.hasCoordinates = prototype.hasCoordinates;
            ret.Width          = prototype.Width;
            ret.Height         = prototype.Height;
            ret.Orientation    = prototype.Orientation;
            ret.imageName      = prototype.imageName;

            ret.image = null;                   // to be assigned directly, if needed for draw; may be by ensureOriginalImageExists()

            ret.m_imageFileName = prototype.m_imageFileName;
            if (prototype.imageUrls != null)
            {
                ret.imageUrls = new Hashtable();
                foreach (string key in prototype.imageUrls.Keys)
                {
                    ret.imageUrls.Add(key, prototype.imageUrls[key]);
                }
            }

            return(ret);
        }
Esempio n. 2
0
        public static PhotoDescr FromSmugmugPhotoGallery(string imageName, Hashtable _imageUrls, Hashtable imageExif)
        {
            PhotoDescr ret = new PhotoDescr();

            ret.imageName = imageName;

            try
            {
                string   sTime = "" + imageExif["DateTimeOriginal"];                            // "2003:08:05 20:12:23"
                string[] split = sTime.Split(new Char[] { ' ' });
                sTime      = split[0].Replace(":", "/") + " " + split[1];
                ret.DTOrig = Convert.ToDateTime(sTime);                                 // local, how time in the camera is set
            }
            catch (Exception)
            {
            }

//	TinyURL: http://heysmile.smugmug.com/photos/24096277-Ti.jpg
//	MediumURL: http://heysmile.smugmug.com/photos/24096277-M.jpg
//	ThumbURL: http://heysmile.smugmug.com/photos/24096277-Th.jpg
//	AlbumURL: http://heysmile.smugmug.com/gallery/576522/1/24096277
//	SmallURL: http://heysmile.smugmug.com/photos/24096277-S.jpg
//	LargeURL: http://heysmile.smugmug.com/photos/24096277-L.jpg
//	OriginalURL: http://heysmile.smugmug.com/photos/24096277-O.jpg

            ret.imageUrls = new Hashtable(_imageUrls);                          // make a local copy

            string thumbUrl = "" + ret.imageUrls["ThumbURL"];

            // Create an Image object from the thumbnail URL.
//			string fileName = "C:\\temp\\aaa.jpg";
//			Image img = null;
            try
            {
                ImageCache.getImage(thumbUrl, true);
//				ret.Width = img.Width;
//				ret.Height = img.Height;
//				ret.image = img;

                m_photoDescrByThumbnailUrl[thumbUrl] = ret;
            }
            // An invalid image will throw an OutOfMemoryException
            // exception
            catch (OutOfMemoryException)
            {
                throw new InvalidOperationException("'" + ret.imageUrls["OriginalURL"] + "' is not a valid and accessible gallery image.");
            }

            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        /// this works on URLs only if a photoDescr has been cached before, and on locals - always
        /// </summary>
        /// <param name="thumbSource"></param>
        /// <returns></returns>
        public static PhotoDescr FromThumbnail(string thumbSource)
        {
            PhotoDescr photoDescr = null;

            if (thumbSource.StartsWith("http://"))
            {
                photoDescr = PhotoDescr.FromSmugmugThumbnail(thumbSource);
            }
            else
            {
                photoDescr = PhotoDescr.FromFileOrZipEntry(null, null, thumbSource, null);
            }

            return(photoDescr);
        }
Esempio n. 4
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (m_photoDescr != null)
     {
         m_photoDescr.releaseImage();
         m_photoDescr = null;
     }
     pictureBox.Image = null;
     if (m_image != null)
     {
         m_image.Dispose();
         m_image = null;
     }
     if (disposing)
     {
         if (components != null)
         {
             components.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 5
0
        public static PhotoDescr FromSmugmugPhotoGallery(string imageName, Hashtable _imageUrls, Hashtable imageExif)
        {
            PhotoDescr ret = new PhotoDescr();

            ret.imageName = imageName;

            try
            {
                string sTime = "" + imageExif["DateTimeOriginal"];		// "2003:08:05 20:12:23"
                string[] split = sTime.Split(new Char[] {' '});
                sTime = split[0].Replace(":", "/") + " " + split[1];
                ret.DTOrig = Convert.ToDateTime(sTime);			// local, how time in the camera is set
            }
            catch (Exception)
            {
            }

            //	TinyURL: http://heysmile.smugmug.com/photos/24096277-Ti.jpg
            //	MediumURL: http://heysmile.smugmug.com/photos/24096277-M.jpg
            //	ThumbURL: http://heysmile.smugmug.com/photos/24096277-Th.jpg
            //	AlbumURL: http://heysmile.smugmug.com/gallery/576522/1/24096277
            //	SmallURL: http://heysmile.smugmug.com/photos/24096277-S.jpg
            //	LargeURL: http://heysmile.smugmug.com/photos/24096277-L.jpg
            //	OriginalURL: http://heysmile.smugmug.com/photos/24096277-O.jpg

            ret.imageUrls = new Hashtable(_imageUrls);		// make a local copy

            string thumbUrl = "" + ret.imageUrls["ThumbURL"];

            // Create an Image object from the thumbnail URL.
            //			string fileName = "C:\\temp\\aaa.jpg";
            //			Image img = null;
            try
            {
                ImageCache.getImage(thumbUrl, true);
            //				ret.Width = img.Width;
            //				ret.Height = img.Height;
            //				ret.image = img;

                m_photoDescrByThumbnailUrl[thumbUrl] = ret;
            }
                // An invalid image will throw an OutOfMemoryException
                // exception
            catch (OutOfMemoryException)
            {
                throw new InvalidOperationException("'"	+ ret.imageUrls["OriginalURL"] + "' is not a valid and accessible gallery image.");
            }

            return ret;
        }
Esempio n. 6
0
        /// <summary>
        /// Make a clone useable for a new PhotoViewerControl, like in DlgPhotoDraw
        /// </summary>
        /// <param name="prototype"></param>
        /// <returns></returns>
        public static PhotoDescr FromPhotoDescr(PhotoDescr prototype)
        {
            PhotoDescr ret = new PhotoDescr();

            ret.DTOrig = prototype.DTOrig;
            ret.Latitude = prototype.Latitude;
            ret.Longitude = prototype.Longitude;
            ret.Altitude = prototype.Altitude;
            ret.hasCoordinates = prototype.hasCoordinates;
            ret.Width = prototype.Width;
            ret.Height = prototype.Height;
            ret.Orientation = prototype.Orientation;
            ret.imageName = prototype.imageName;

            ret.image = null;	// to be assigned directly, if needed for draw; may be by ensureOriginalImageExists()

            ret.m_imageFileName = prototype.m_imageFileName;
            if(prototype.imageUrls != null)
            {
                ret.imageUrls = new Hashtable();
                foreach(string key in prototype.imageUrls.Keys)
                {
                    ret.imageUrls.Add(key, prototype.imageUrls[key]);
                }
            }

            return ret;
        }
Esempio n. 7
0
        /// <summary>
        /// fileName can be in form "C:\\aaa\aaa.zip|bbb\bbb.jpg"
        /// imageName will be generated if name=null is passed (in the form of "bbb.jpg")
        /// </summary>
        /// <param name="zip"></param>
        /// <param name="zipEntry"></param>
        /// <param name="fileName"></param>
        /// <param name="imageName"></param>
        /// <returns></returns>
        public static PhotoDescr FromFileOrZipEntry(ZipFile zip, ZipEntry zipEntry, string fileName, string name)
        {
            PhotoDescr ret = new PhotoDescr();

            Stream stream = null;
            bool doCloseZip = false;
            ret.imageName = name;

            if(zip == null)
            {
                int pos = fileName.IndexOf("|");
                if(pos >= 0)
                {
                    // this is a .zip or .gpz file
                    string zipFileName = fileName.Substring(0, pos);

                    if (!File.Exists(zipFileName))
                    {
                        LibSys.StatusBar.Error("Failed to open Zip");
                        throw new InvalidOperationException("'" + zipFileName + "' not found or not a valid zip file");
                    }

                    zip = new ZipFile(zipFileName);

                    doCloseZip = true;
                    string photoFileName = fileName.Substring(pos + 1);

                    zipEntry = zip.GetEntry(photoFileName);
                    if (zipEntry == null)
                    {
                        zip.Close();
                        throw new InvalidOperationException("'" + photoFileName + "' is not found inside " + zipFileName);
                    }
                }
                else
                {
                    // plain file
                    ret.imageSource = fileName;
                    if(ret.imageName == null)
                    {
                        // generate image name based on file name:
                        ret.imageName = imageNameFromFileName(Path.GetFileName(fileName));
                    }
                }
            }

            if(zip != null)
            {
                ret.imageSource = zip.Name + "|" + zipEntry.Name;
                if(ret.imageName == null)
                {
                    // generate image name based on file name:
                    int pos = zipEntry.Name.LastIndexOf("\\");
                    string imageFileName;
                    if(pos >= 0)
                    {
                        imageFileName = zipEntry.Name.Substring(pos + 1);
                    }
                    else
                    {
                        imageFileName = zipEntry.Name;
                    }
                    ret.imageName = imageNameFromFileName(imageFileName);
                }

                stream = zip.GetInputStream(zipEntry);
            }

            // Create an Image object from the specified file.
            Image img = null;
            try
            {
                img = (zip == null) ? Image.FromFile(fileName, true) : new Bitmap(stream);
                ret.Width = img.Width;
                ret.Height = img.Height;
                ret.image = img;
            }
                // An invalid image will throw an OutOfMemoryException
            catch (OutOfMemoryException)
            {
                if(doCloseZip)
                {
                    zip.Close();
                }
                throw new InvalidOperationException("'"	+ fileName + "' is not a valid image file.");
            }

            if(doCloseZip)
            {
                zip.Close();
            }

            try
            {
                //	<tagMetadata id="36867" category="EXIF">
                //		<name>DTOrig</name>
                //		<description>Date and time when the original image data was generated. For a DSC, the date and time when the picture was taken. The format is YYYY:MM:DD HH:MM:SS with time shown in 24-hour format and the date and time separated by one blank character (0x2000). The character string length is 20 bytes including the NULL terminator. When the field is empty, it is treated as unknown.</description>
                //	</tagMetadata>
                //	<tagMetadata id="36868" category="EXIF">
                //		<name>DTDigitized</name>
                //		<description>Date and time when the image was stored as digital data. If, for example, an image was captured by DSC and at the same time the file was recorded, then DateTimeOriginal and DateTimeDigitized will have the same contents. The format is YYYY:MM:DD HH:MM:SS with time shown in 24-hour format and the date and time separated by one blank character (0x2000). The character string length is 20 bytes including the NULL terminator. When the field is empty, it is treated as unknown.</description>
                //	</tagMetadata>

                PropertyItem prop = img.GetPropertyItem(36867);
                switch(prop.Type)
                {
                    case 2:
                        string sTime = Project.ByteArrayToStr(prop.Value);		// "2003:08:05 20:12:23"
                        string[] split = sTime.Split(new Char[] {' '});
                        sTime = split[0].Replace(":", "/") + " " + split[1];
                        ret.DTOrig = Convert.ToDateTime(sTime);			// local, how time in the camera is set
                        break;
                }
            }
            catch (Exception)
            {
            }

            try
            {
                //	<tagMetadata id="1" category="GPS">
                //		<name>GPSLatitudeRef</name>
                //		<description>Indicates whether the latitude is north or south latitude.
                //		The ASCII value 'N' indicates north latitude, and 'S' is south latitude.</description>
                //		<valueOptions>
                //			<option key="N" keyType="CHAR" value="North latitude" />
                //			<option key="S" keyType="CHAR" value="South latitude" />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                //	<tagMetadata id="2" category="GPS">
                //		<name>GPSLatitude</name>
                //		<description>Indicates the latitude. The latitude is expressed as three
                //		RATIONAL values giving the degrees, minutes, and seconds, respectively.
                //		When degrees, minutes and seconds are expressed, the format is dd/1,mm/1,ss/1.
                //		When degrees and minutes are used and, for example, fractions of minutes are
                //		given up to two decimal places, the format is dd/1,mmmm/100,0/1.</description>
                //	</tagMetadata>
                //	<tagMetadata id="3" category="GPS">
                //		<name>GPSLongitudeRef</name>
                //		<description>Indicates whether the longitude is east or west longitude.
                //		The ASCII value 'E' indicates east longitude, and 'W' is west longitude.</description>
                //		<valueOptions>
                //			<option key="E" keyType="CHAR" value="East longitude" />
                //			<option key="W" keyType="CHAR" value="West longitude" />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                //	<tagMetadata id="4" category="GPS">
                //		<name>GPSLongitude</name>
                //		<description>Indicates the longitude. The longitude is expressed as three
                //		RATIONAL values giving the degrees, minutes, and seconds, respectively.
                //		When degrees, minutes and seconds are expressed, the format is ddd/1,mm/1,ss/1.
                //		When degrees and minutes are used and, for example, fractions of minutes are
                //		given up to two decimal places, the format is ddd/1,mmmm/100,0/1.</description>
                //	</tagMetadata>

                string sLatRef = null;
                double lat = 0.0d;
                string sLngRef = null;
                double lng = 0.0d;

                PropertyItem prop = img.GetPropertyItem(1);
                switch(prop.Type)
                {
                    case 2:
                        sLatRef = Project.ByteArrayToStr(prop.Value);		// "N" or "S"
                        break;
                }

                prop = img.GetPropertyItem(2);
                switch(prop.Type)
                {
                    case 5:
                        lat = ParseRationalCoord(prop);		// "51.0 56.0 33.123"
                        break;
                }

                prop = img.GetPropertyItem(3);
                switch(prop.Type)
                {
                    case 2:
                        sLngRef = Project.ByteArrayToStr(prop.Value);		// "W" or "E"
                        break;
                }

                prop = img.GetPropertyItem(4);
                switch(prop.Type)
                {
                    case 5:
                        lng = ParseRationalCoord(prop);		// "4.0 22.0 33.123"
                        break;
                }

                if(sLatRef != null && sLngRef != null)
                {
                    bool isWest = sLngRef.ToLower().StartsWith("w");
                    bool isSouth = sLatRef.ToLower().StartsWith("s");
                    if(isSouth)
                    {
                        lat = -lat;
                    }
                    if(isWest)
                    {
                        lng = -lng;
                    }
                    ret.Latitude = lat;
                    ret.Longitude = lng;
                    ret.hasCoordinates = true;
                }
            }
            catch (Exception)
            {
            }

            try
            {
                //	<tagMetadata id="274" category="">
                //		<name>Orientation</name>
                //		<description>Image orientation viewed in terms of rows and columns.</description>
                //		<valueOptions>
                //			<option key="1" value="The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side." />
                //			<option key="2" value="The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side." />
                //			<option key="3" value="The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side." />
                //			<option key="4" value="The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side." />
                //			<option key="5" value="The 0th row is the visual left-hand side of of the image, and the 0th column is the visual top." />
                //			<option key="6" value="The 0th row is the visual right-hand side of of the image, and the 0th column is the visual top." />
                //			<option key="7" value="The 0th row is the visual right-hand side of of the image, and the 0th column is the visual bottom." />
                //			<option key="8" value="The 0th row is the visual left-hand side of of the image, and the 0th column is the visual bottom." />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                PropertyItem prop = img.GetPropertyItem(274);
                switch(prop.Type)
                {
                    case 3:
                        ret.Orientation = (int)prop.Value[0];		// 6 and 8 are known to appear here
                        break;
                }
            }
            catch (Exception)
            {
            }

            return ret;
        }
Esempio n. 8
0
 /// <summary> 
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose( bool disposing )
 {
     if(m_photoDescr != null)
     {
         m_photoDescr.releaseImage();
         m_photoDescr = null;
     }
     pictureBox.Image = null;
     if(m_image != null)
     {
         m_image.Dispose();
         m_image = null;
     }
     if( disposing )
     {
         if(components != null)
         {
             components.Dispose();
         }
     }
     base.Dispose( disposing );
 }
Esempio n. 9
0
        public static Waypoint createPhotoTrackpoint(PhotoDescr photoDescr, TimeSpan photoTimeShift, int tzId)
        {
            if(photoDescr.hasCoordinates)
            {
                // There is EXIF coordinates set, use it.
                GeoCoord loc = new GeoCoord(photoDescr.Longitude, photoDescr.Latitude, photoDescr.Altitude);
                string name = photoDescr.imageName;
                string source = photoDescr.imageSource;
                string url = photoDescr.imageUrl;
                Waypoint wpt0 = new Waypoint(loc, Project.localToZulu(photoDescr.DTOrig),
                                                    LiveObjectTypes.LiveObjectTypeWaypoint, -1, name, source, url) ;
                wpt0.Desc = photoDescr.imageName;
                wpt0.ThumbImage = photoDescr.ThumbnailImage;
                wpt0.ThumbSource = photoDescr.imageThumbSource;
                wpt0.ThumbPosition = Project.thumbPosition;
                wpt0.imageWidth = photoDescr.Width;
                wpt0.imageHeight = photoDescr.Height;
                wpt0.PhotoTimeShift = new TimeSpan(0L);
                // we need to shift the timestamp a bit if the spot is taken:
                while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime))
                {
                    DateTime tmp = wpt0.DateTime;
                    wpt0.DateTime = tmp.AddMilliseconds(1);
                }
                // make sure the new waypoint is accounted for in the cache:
                WaypointsWithThumbs.Add(wpt0.DateTime, wpt0);
                CurrentWptIndex = WaypointsWithThumbs.Count - 1;
                WaypointsCache.addWaypoint(wpt0);

                return wpt0;
            }

            if(photoDescr.DTOrig.Equals(DateTime.MinValue))
            {
                // try to get it from file name:
                photoDescr.ensureImageExists();
                Waypoint wpt0 = WaypointsCache.getWaypointByName(photoDescr.imageName);
                if(wpt0 != null)
                {
                    //wpt0.Desc = photoDescr.imageName;
                    wpt0.ThumbImage = photoDescr.ThumbnailImage;
                    wpt0.ThumbSource = photoDescr.imageThumbSource;
                    wpt0.ThumbPosition = Project.thumbPosition;
                    wpt0.imageWidth = photoDescr.Width;
                    wpt0.imageHeight = photoDescr.Height;
                    wpt0.PhotoTimeShift = new TimeSpan(0L);
                    // we need to shift the timestamp a bit if the spot is taken:
                    while(WaypointsWithThumbs.ContainsKey(wpt0.DateTime))
                    {
                        DateTime tmp = wpt0.DateTime;
                        wpt0.DateTime = tmp.AddMilliseconds(1);
                    }
                    // make sure the new waypoint is accounted for in the cache:
                    WaypointsWithThumbs.Add(wpt0.DateTime, wpt0);
                    CurrentWptIndex = WaypointsWithThumbs.Count - 1;

                    return wpt0;
                }
                else
                {
                    registerUnrelatedPhoto(photoDescr);
                }
                return null;
            }

            TimeSpan timeZoneSpan = MyTimeZone.timeSpanById(tzId);
            DateTime timeStamp = Project.localToZulu(photoDescr.DTOrig + photoTimeShift + MyTimeZone.zoneTimeShift - timeZoneSpan);
            //LibSys.StatusBar.Trace("adjusted zulu time=" + timeStamp);
            registerImageTimestamp(timeStamp);

            if(photoDescr.imageSourceIsLocal && photoDescr.image == null)
            {
                // try to get it from file name:
                photoDescr.ensureImageExists();
                registerUnrelatedPhoto(photoDescr);
                return null;
            }
            Waypoint wpt = null;
            Waypoint wpt1;
            Waypoint wpt2;
            // wpt2 is hit if exact match on the timestamp; wpt1 may turn null, but not wpt2.
            if(WaypointsCache.trackpointByTime(timeStamp, out wpt1, out wpt2))
            {
                // create duplicate waypoint and add it to the same track - to hold the image
                wpt = new Waypoint(wpt2);
                if(wpt1 == null)
                {
                    // exact match on wpt2
                }
                else
                {
                    // somewhere between wpt1 and wpt2
                    double dt = (wpt2.DateTime - wpt1.DateTime).Ticks;
                    double dt1 = (timeStamp - wpt1.DateTime).Ticks;
                    if(dt > 0)
                    {
                        double ratio =  dt1 / dt;
                        wpt.Location.Lat = wpt1.Location.Lat + (wpt2.Location.Lat - wpt1.Location.Lat) * ratio;
                        wpt.Location.Lng = wpt1.Location.Lng + (wpt2.Location.Lng - wpt1.Location.Lng) * ratio;
                    }
                }
                wpt.DateTime = timeStamp;
                wpt.Desc = photoDescr.imageName;
                Track trk = WaypointsCache.getTrackById(wpt.TrackId);
                // we need to shift the timestamp a bit if the spot is taken:
                while(WaypointsWithThumbs.ContainsKey(wpt.DateTime) || trk.Trackpoints.ContainsKey(wpt.DateTime))
                {
                    DateTime tmp = wpt.DateTime;
                    wpt.DateTime = tmp.AddMilliseconds(1);
                }
                trk.insertWaypoint(wpt);
                wpt.ThumbImage = photoDescr.ThumbnailImage;
                wpt.ThumbSource = photoDescr.imageThumbSource;
                wpt.ThumbPosition = Project.thumbPosition;
                wpt.imageWidth = photoDescr.Width;
                wpt.imageHeight = photoDescr.Height;
                wpt.PhotoTimeShift = photoTimeShift;
                // make sure the new waypoint is accounted for in the cache:
                WaypointsWithThumbs.Add(wpt.DateTime, wpt);
                CurrentWptIndex = WaypointsWithThumbs.Count - 1;
            }
            else
            {
                registerUnrelatedPhoto(photoDescr);
            }
            return wpt;
        }
Esempio n. 10
0
        // can be called from different thread:
        public static void BringFormUp(PhotoDescr photoDescr, Waypoint wpt)
        {
            try
            {
                if(wpt != null)
                {
                    m_wpt = wpt;
                    PhotoWaypoints.SetCurrentWaypoint(m_wpt);
                }
                else
                {
                    m_wpt = PhotoWaypoints.CurrentWaypoint();
                }

                if(photoDescr == null)
                {
                    try
                    {
                        photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource);
                    }
                        // An invalid image will throw an OutOfMemoryException
                        // exception
                    catch (OutOfMemoryException)
                    {
                    }
                }
                else if(wpt == null)
                {
                    m_wpt = null;	// from Unrelated photos
                }
                m_photoDescr = photoDescr;

                if(This == null)
                {
                    if(Project.mainForm.InvokeRequired)
                    {
                        Project.mainForm.Invoke(new MethodInvoker(RunPhotoFullSizeForm));
                    }
                    else
                    {
                        RunPhotoFullSizeForm();
                    }
                }
                else
                {
                    if(Project.mainForm.InvokeRequired)
                    {
                        Project.mainForm.Invoke(new MethodInvoker(RunBringUp));
                    }
                    else
                    {
                        RunBringUp();
                    }
                }
            }
            catch {}
        }
Esempio n. 11
0
        private void setQuickPhotoPreview(PhotoDescr photoDescr)
        {
            if(Project.photoDoPreview)
                {
                    photoViewerControl.photoDescr = photoDescr;
                }
                else
                {
                    photoViewerControl.photoDescr = null;
                }

                photoViewerControl.Refresh();	// even if img==null, need to clear the picture
        }
Esempio n. 12
0
 private void setMessageLabel(PhotoDescr photoDescr, Waypoint wpt)
 {
     if(wpt != null && wpt.DateTime.CompareTo(timeZero) > 0)
     {
         this.messageLabel.Text = "" + Project.zuluToLocal(wpt.DateTime) + "   " + photoDescr.Width + " x " + photoDescr.Height;
     }
     else
     {
         this.messageLabel.Text = "[no time stamp]   " + photoDescr.Width + " x " + photoDescr.Height;
     }
 }
Esempio n. 13
0
 public void setParameters(Waypoint wpt, PhotoDescr photoDescr)
 {
     m_photoDescr = photoDescr;
     m_wpt = wpt;
     parametersChanged();
 }
Esempio n. 14
0
        public static Image rebuildThumbnailImage(string thumbSource)
        {
            Image ret = null;

            if (thumbSource.ToLower().StartsWith("http://"))
            {
                // a gallery, and actual URL of the thumbnail

                ret = ImageCache.getImage(thumbSource, true);
            }
            else
            {
                // local file, containing large image.

                PhotoDescr pd = PhotoDescr.FromFileOrZipEntry(null, null, thumbSource, "none");

                float imageRatio = (float)pd.image.Width / (float)pd.image.Height;
                float panelRatio = (float)Project.thumbWidth / (float)Project.thumbHeight;

                int thumbWidth;
                int thumbHeight;

                if (imageRatio > panelRatio)                    // image wider
                {
                    thumbWidth  = Project.thumbWidth;
                    thumbHeight = (int)(thumbWidth / imageRatio);
                }
                else
                {
                    thumbHeight = Project.thumbHeight;
                    thumbWidth  = (int)(thumbHeight * imageRatio);
                }

                // make a thumbnail bitmap:
                Bitmap thumb = new Bitmap(pd.image, new Size(thumbWidth, thumbHeight));
                // the following produces ugly big unfocused thumbnail, so we stay with Bitmap for now:
                //Image thumb = photoDescr.image.GetThumbnailImage(Project.thumbWidth, Project.thumbHeight, null, IntPtr.Zero);
                // rotate thumbnail based on photoDescr.Orientation.
                switch (pd.Orientation)
                {
                // see PhotoDescr.cs for EXIF orientation codes:
                case 4:
                    thumb.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case 8:
                    thumb.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;

                case 6:
                    thumb.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;
                }
                if (thumbSource.IndexOf("|") != -1)
                {
                    ImageCache.putImage(thumb, thumbSource, null, true);                        // zipfile - putImage() will generate local temp file
                }
                else
                {
                    ImageCache.putImage(thumb, thumbSource, thumbSource, true);
                }
                ret = thumb;

                pd.releaseImage();
            }

            return(ret);
        }
Esempio n. 15
0
        /// <summary>
        /// fileName can be in form "C:\\aaa\aaa.zip|bbb\bbb.jpg"
        /// imageName will be generated if name=null is passed (in the form of "bbb.jpg")
        /// </summary>
        /// <param name="zip"></param>
        /// <param name="zipEntry"></param>
        /// <param name="fileName"></param>
        /// <param name="imageName"></param>
        /// <returns></returns>
        public static PhotoDescr FromFileOrZipEntry(ZipFile zip, ZipEntry zipEntry, string fileName, string name)
        {
            PhotoDescr ret = new PhotoDescr();

            Stream stream     = null;
            bool   doCloseZip = false;

            ret.imageName = name;

            if (zip == null)
            {
                int pos = fileName.IndexOf("|");
                if (pos >= 0)
                {
                    // this is a .zip or .gpz file
                    string zipFileName = fileName.Substring(0, pos);

                    if (!File.Exists(zipFileName))
                    {
                        LibSys.StatusBar.Error("Failed to open Zip");
                        throw new InvalidOperationException("'" + zipFileName + "' not found or not a valid zip file");
                    }

                    zip = new ZipFile(zipFileName);

                    doCloseZip = true;
                    string photoFileName = fileName.Substring(pos + 1);

                    zipEntry = zip.GetEntry(photoFileName);
                    if (zipEntry == null)
                    {
                        zip.Close();
                        throw new InvalidOperationException("'" + photoFileName + "' is not found inside " + zipFileName);
                    }
                }
                else
                {
                    // plain file
                    ret.imageSource = fileName;
                    if (ret.imageName == null)
                    {
                        // generate image name based on file name:
                        ret.imageName = imageNameFromFileName(Path.GetFileName(fileName));
                    }
                }
            }

            if (zip != null)
            {
                ret.imageSource = zip.Name + "|" + zipEntry.Name;
                if (ret.imageName == null)
                {
                    // generate image name based on file name:
                    int    pos = zipEntry.Name.LastIndexOf("\\");
                    string imageFileName;
                    if (pos >= 0)
                    {
                        imageFileName = zipEntry.Name.Substring(pos + 1);
                    }
                    else
                    {
                        imageFileName = zipEntry.Name;
                    }
                    ret.imageName = imageNameFromFileName(imageFileName);
                }

                stream = zip.GetInputStream(zipEntry);
            }

            // Create an Image object from the specified file.
            Image img = null;

            try
            {
                img        = (zip == null) ? Image.FromFile(fileName, true) : new Bitmap(stream);
                ret.Width  = img.Width;
                ret.Height = img.Height;
                ret.image  = img;
            }
            // An invalid image will throw an OutOfMemoryException
            catch (OutOfMemoryException)
            {
                if (doCloseZip)
                {
                    zip.Close();
                }
                throw new InvalidOperationException("'" + fileName + "' is not a valid image file.");
            }

            if (doCloseZip)
            {
                zip.Close();
            }

            try
            {
                //	<tagMetadata id="36867" category="EXIF">
                //		<name>DTOrig</name>
                //		<description>Date and time when the original image data was generated. For a DSC, the date and time when the picture was taken. The format is YYYY:MM:DD HH:MM:SS with time shown in 24-hour format and the date and time separated by one blank character (0x2000). The character string length is 20 bytes including the NULL terminator. When the field is empty, it is treated as unknown.</description>
                //	</tagMetadata>
                //	<tagMetadata id="36868" category="EXIF">
                //		<name>DTDigitized</name>
                //		<description>Date and time when the image was stored as digital data. If, for example, an image was captured by DSC and at the same time the file was recorded, then DateTimeOriginal and DateTimeDigitized will have the same contents. The format is YYYY:MM:DD HH:MM:SS with time shown in 24-hour format and the date and time separated by one blank character (0x2000). The character string length is 20 bytes including the NULL terminator. When the field is empty, it is treated as unknown.</description>
                //	</tagMetadata>

                PropertyItem prop = img.GetPropertyItem(36867);
                switch (prop.Type)
                {
                case 2:
                    string   sTime = Project.ByteArrayToStr(prop.Value);                                        // "2003:08:05 20:12:23"
                    string[] split = sTime.Split(new Char[] { ' ' });
                    sTime      = split[0].Replace(":", "/") + " " + split[1];
                    ret.DTOrig = Convert.ToDateTime(sTime);                                             // local, how time in the camera is set
                    break;
                }
            }
            catch (Exception)
            {
            }

            try
            {
                //	<tagMetadata id="1" category="GPS">
                //		<name>GPSLatitudeRef</name>
                //		<description>Indicates whether the latitude is north or south latitude.
                //		The ASCII value 'N' indicates north latitude, and 'S' is south latitude.</description>
                //		<valueOptions>
                //			<option key="N" keyType="CHAR" value="North latitude" />
                //			<option key="S" keyType="CHAR" value="South latitude" />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                //	<tagMetadata id="2" category="GPS">
                //		<name>GPSLatitude</name>
                //		<description>Indicates the latitude. The latitude is expressed as three
                //		RATIONAL values giving the degrees, minutes, and seconds, respectively.
                //		When degrees, minutes and seconds are expressed, the format is dd/1,mm/1,ss/1.
                //		When degrees and minutes are used and, for example, fractions of minutes are
                //		given up to two decimal places, the format is dd/1,mmmm/100,0/1.</description>
                //	</tagMetadata>
                //	<tagMetadata id="3" category="GPS">
                //		<name>GPSLongitudeRef</name>
                //		<description>Indicates whether the longitude is east or west longitude.
                //		The ASCII value 'E' indicates east longitude, and 'W' is west longitude.</description>
                //		<valueOptions>
                //			<option key="E" keyType="CHAR" value="East longitude" />
                //			<option key="W" keyType="CHAR" value="West longitude" />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                //	<tagMetadata id="4" category="GPS">
                //		<name>GPSLongitude</name>
                //		<description>Indicates the longitude. The longitude is expressed as three
                //		RATIONAL values giving the degrees, minutes, and seconds, respectively.
                //		When degrees, minutes and seconds are expressed, the format is ddd/1,mm/1,ss/1.
                //		When degrees and minutes are used and, for example, fractions of minutes are
                //		given up to two decimal places, the format is ddd/1,mmmm/100,0/1.</description>
                //	</tagMetadata>

                string sLatRef = null;
                double lat     = 0.0d;
                string sLngRef = null;
                double lng     = 0.0d;

                PropertyItem prop = img.GetPropertyItem(1);
                switch (prop.Type)
                {
                case 2:
                    sLatRef = Project.ByteArrayToStr(prop.Value);                                       // "N" or "S"
                    break;
                }

                prop = img.GetPropertyItem(2);
                switch (prop.Type)
                {
                case 5:
                    lat = ParseRationalCoord(prop);                                     // "51.0 56.0 33.123"
                    break;
                }

                prop = img.GetPropertyItem(3);
                switch (prop.Type)
                {
                case 2:
                    sLngRef = Project.ByteArrayToStr(prop.Value);                                       // "W" or "E"
                    break;
                }

                prop = img.GetPropertyItem(4);
                switch (prop.Type)
                {
                case 5:
                    lng = ParseRationalCoord(prop);                                     // "4.0 22.0 33.123"
                    break;
                }

                if (sLatRef != null && sLngRef != null)
                {
                    bool isWest  = sLngRef.ToLower().StartsWith("w");
                    bool isSouth = sLatRef.ToLower().StartsWith("s");
                    if (isSouth)
                    {
                        lat = -lat;
                    }
                    if (isWest)
                    {
                        lng = -lng;
                    }
                    ret.Latitude       = lat;
                    ret.Longitude      = lng;
                    ret.hasCoordinates = true;
                }
            }
            catch (Exception)
            {
            }

            try
            {
                //	<tagMetadata id="274" category="">
                //		<name>Orientation</name>
                //		<description>Image orientation viewed in terms of rows and columns.</description>
                //		<valueOptions>
                //			<option key="1" value="The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side." />
                //			<option key="2" value="The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side." />
                //			<option key="3" value="The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side." />
                //			<option key="4" value="The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side." />
                //			<option key="5" value="The 0th row is the visual left-hand side of of the image, and the 0th column is the visual top." />
                //			<option key="6" value="The 0th row is the visual right-hand side of of the image, and the 0th column is the visual top." />
                //			<option key="7" value="The 0th row is the visual right-hand side of of the image, and the 0th column is the visual bottom." />
                //			<option key="8" value="The 0th row is the visual left-hand side of of the image, and the 0th column is the visual bottom." />
                //			<optionOtherwise value="reserved" />
                //		</valueOptions>
                //	</tagMetadata>
                PropertyItem prop = img.GetPropertyItem(274);
                switch (prop.Type)
                {
                case 3:
                    ret.Orientation = (int)prop.Value[0];                                       // 6 and 8 are known to appear here
                    break;
                }
            }
            catch (Exception)
            {
            }

            return(ret);
        }
Esempio n. 16
0
        public DlgPhotoDraw(Waypoint wpt, PhotoDescr photoDescr)
        {
            if(photoDescr != null)
            {
                // from DlgPhotoFullSize, wpt may be null
                m_photoDescr = PhotoDescr.FromPhotoDescr(photoDescr);		// with null image
                m_photoDescr.imageDisposable = false;
                m_photoDescr.ensureOriginalImageExists();		// local will be still invoked if not a gallery
            }
            else
            {
                // from right-click on a waypoint; wpt must be non-null
                try
                {
                    m_photoDescr = PhotoDescr.FromThumbnail(wpt.ThumbSource);
                    m_photoDescr.imageDisposable = false;
                    m_photoDescr.ensureOriginalImageExists();		// local will be still invoked if not a gallery
                }
                    // An invalid image will throw an OutOfMemoryException
                    // exception
                catch (OutOfMemoryException)
                {
                    throw new Exception("Corrupted image file?");
                }
            }
            originalOrientation = m_photoDescr.Orientation;
            m_photoDescr.Orientation = 1;			// will force display to actual orientation, no adjustment
            originalBitmap = new Bitmap(m_photoDescr.image);
            whRatio = (double)originalBitmap.Width / (double)originalBitmap.Height;

            foreach(PropertyItem item in m_photoDescr.image.PropertyItems)
            {
                //string str = "" + item.Type + ": " + item.Id + "=" + item.Value;
                //LibSys.StatusBar.Trace(str);
                originalBitmap.SetPropertyItem(item);
            }

            m_wpt = wpt;

            InitializeComponent();

            addExifCoordsCheckBox.Enabled = (m_wpt != null);
            addExifCoordsCheckBox.Checked = m_addExifCoords;

            this.linkToWptLinkLabel.Enabled = (m_wpt == null || m_wpt.TrackId == -1);

            this.photoViewerControl = new LibSys.PhotoViewerControl();
            this.picturePanel.Controls.AddRange(new System.Windows.Forms.Control[] { this.photoViewerControl});
            //
            // photoViewerControl
            //
            this.photoViewerControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.photoViewerControl.Name = "photoViewerControl";
            //this.photoViewerControl.photoDescr = null;
            this.photoViewerControl.TabIndex = 1;

            photoViewerControl.fitToSize = m_fitToSize;
            fitToSizeCheckBox.Checked = m_fitToSize;
            this.fitToSizeCheckBox.CheckedChanged += new System.EventHandler(this.fitToSizeCheckBox_CheckedChanged);

            if(m_wpt != null && m_wpt.TrackId != -1)
            {
                timeTptRadioButton.Checked = true;
                this.timePanel.Enabled = true;
            }
            else
            {
                timeExifRadioButton.Checked = true;
                timePanel.Enabled = false;
            }

            setTextTextBox();

            widthTextBox.Text = "" + originalBitmap.Width;		// Y will be set in validation
            widthTextBox_Validating(null, null);

            draw(false);

            if(Project.fitsScreen(m_dlgSizeX, m_dlgSizeY, m_dlgSizeWidth, m_dlgSizeHeight))
            {
                inResize = true;
                this.Location = new Point(m_dlgSizeX, m_dlgSizeY);
                this.ClientSize = new System.Drawing.Size(m_dlgSizeWidth, m_dlgSizeHeight);		// causes Resize()
            }

            // PhotoProperties related:
            // Create an instance of a ListView column sorter and
            // assign it to the _listView control.
            lvwColumnSorter = new ListViewColumnSorter();
            this._listView.ListViewItemSorter = lvwColumnSorter;

            _resultOptions = new ResultOptions();

            // end of PhotoProperties related.

            positionComboBox.SelectedIndex = m_position;
            this.positionComboBox.SelectedIndexChanged += new System.EventHandler(this.positionComboBox_SelectedIndexChanged);

            m_fontSize = (int)Math.Round(Math.Max(originalBitmap.Width / 50.0d, m_fontSize));
            fontNumericUpDown.Value = Math.Min(m_fontSize, fontNumericUpDown.Maximum);

            qualityNumericUpDown.Value = Project.photoSaveQuality;
            this.qualityNumericUpDown.ValueChanged += new System.EventHandler(this.qualityNumericUpDown_ValueChanged);

            applyTextCheckBox.Checked = true;
            pickColorButton.BackColor = m_color;
            pickBgColorButton.BackColor = m_bgColor;
            this.useBgColorCheckBox.Checked = m_useBgColor;

            this.Text += " - " + m_photoDescr.imageName;

            switch(originalOrientation)
            {
                    // see PhotoDescr.cs for EXIF orientation codes:
            //				case 4:
            //					//thumb.RotateFlip(RotateFlipType.Rotate180FlipNone);
            //					break;
                case 8:
                    this.rotate270RadioButton.Checked = true;
                    //thumb.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;
                case 6:
                    this.rotate90RadioButton.Checked = true;
                    //thumb.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;
                default:
                    this.rotate0RadioButton.Checked = true;
                    break;
            }

            this.saveButton.Enabled = false;
            this.previewLinkLabel.Enabled = false;

            Project.setDlgIcon(this);
        }
Esempio n. 17
0
        public DlgMakeWaypoint(CameraManager cameraManager, PhotoDescr photoDescr, Waypoint wpt)
            : this(cameraManager)
        {
            this.TopMost = true;

            if(wpt == null)
            {
                m_clickLocation = m_cameraManager.Location.Clone();
                m_clickLocation.Elev = 0.0d;
            }
            else
            {
                m_clickLocation = wpt.Location.Clone();
                elevLabel.Text = wpt.TrackId == -1 ? "Elevation:" : "Altitude";
            }
            setCoordFields(m_clickLocation);

            m_photoDescr = photoDescr;

            this.waypointNameTextBox.Text = m_photoDescr.imageName;
            this.urlTextBox.Text = m_photoDescr.imageUrl;
            this.detailTextBox.Text = m_photoDescr.imageSource;
            this.timePicker.dateTime = m_photoDescr.DTOrig;

            // all we can realistically change here is coordinates and elevation, so disable other conrols:
            this.symbolTextBox.Enabled = false;
            this.waypointNameTextBox.Enabled = false;
            this.waypointTypeComboBox.Enabled = false;
            this.urlNameTextBox.Enabled = false;
            this.urlTextBox.Enabled = false;
            this.detailTextBox.Enabled = false;
            this.commentTextBox.Enabled = false;
            //this.timePicker.Enabled = false;

            Project.setDlgIcon(this);
            waypointNameTextBox.Focus();
        }
Esempio n. 18
0
        private void deleteButton_Click(object sender, System.EventArgs e)
        {
            if(m_photoDescr != null && m_photoDescr.imageSourceIsLocal)
            {
                string imageSource = m_photoDescr.imageSource;
                try
                {
                    string msg;
                    int pos = imageSource.IndexOf("|");
                    if(pos > 0)
                    {
                        // this is a .zip or .gpz file
                        string zipFileName = imageSource.Substring(0, pos);
                        string photoFileName = imageSource.Substring(pos + 1);
                        msg = "Will permanently delete entry '" + photoFileName + "' from the zip archive '" + zipFileName
                                    + "'.\n\nThe zip archive file will NOT be deleted.\n\nAre you sure?";
                    }
                    else
                    {
                        // plain file
                        msg = "Will permanently delete file '" + imageSource + "' from disk.\n\nAre you sure?";
                    }

                    string fileToDelete = null;

                    if(Project.YesNoBox(this, msg))
                    {
                        if(m_wpt != null)
                        {
                            if(m_wpt.TrackId == -1)
                            {
                                WaypointsCache.RemoveWaypointById(m_wpt.Id);
                            }
                            PhotoWaypoints.RemoveWaypoint(m_wpt);		// from track too, if any

                            photoViewerControl.photoDescr = null;

                            fileToDelete = m_photoDescr.deleteFromDisk();

                            if(preview())		// will find current waypoint, if any, and set m_photoDescr
                            {
                                setPhotoDetail();
                                photoViewerControl.Refresh();
                            }
                            else
                            {
                                // no image to display, need to wrap up
                                m_photoDescr = null;
                                this.Close();
                            }
                            PictureManager.This.Refresh();
                        }
                        else
                        {
                            PhotoWaypoints.RemoveUnrelatedById(m_photoDescr.Id);

                            fileToDelete = m_photoDescr.deleteFromDisk();

                            if(PhotoWaypoints.PhotosUnrelated.Count > 0)
                            {
                                photoViewerControl.photoDescr = m_photoDescr = (PhotoDescr)PhotoWaypoints.PhotosUnrelated.GetByIndex(0);
                                setPhotoDetail();
                                photoViewerControl.Refresh();
                                this.setupButtons();
                                this.BringToFront();
                            }
                            else
                            {
                                photoViewerControl.photoDescr = m_photoDescr = null;
                                this.Close();
                            }
                        }

                        DlgPhotoManager.sync(true);

                        if(fileToDelete != null)
                        {
                            GC.Collect();
                            FileInfo fi = new FileInfo(fileToDelete);
                            fi.Delete();
                        }
                    }
                }
                catch (Exception exc)
                {
                    Project.ErrorBox(this, "Failed to delete " + imageSource + "\n\nException: " + exc.Message);
                    this.Close();
                }
            }
        }
Esempio n. 19
0
 private static void registerUnrelatedPhoto(PhotoDescr photoDescr)
 {
     try
     {
         if(PhotosUnrelated.ContainsKey(photoDescr.imageSource))
         {
             PhotosUnrelated.Remove(photoDescr.imageSource);
         }
         PhotosUnrelated.Add(photoDescr.imageSource, photoDescr);
     }
     catch {}
 }
Esempio n. 20
0
        /// <summary>
        /// returns true if it could actually find something to display
        /// </summary>
        /// <returns></returns>
        private bool preview()
        {
            bool ret = false;

            disableButtons();
            // Create an Image object from the specified file.
            try
            {
                m_wpt = PhotoWaypoints.CurrentWaypoint();
                if(m_wpt != null)
                {
                    PhotoDescr photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource);

                    photoViewerControl.photoDescr = m_photoDescr = photoDescr;

                    setPhotoDetail();
                    if(m_keepInView)
                    {
                        PictureManager.This.CameraManager.keepInView(m_wpt.Location);
                    }
                    PictureManager.This.CameraManager.MarkLocation(m_wpt.Location, 0);
                    ret = true;
                }
                else
                {
                    photoViewerControl.photoDescr = m_photoDescr = null;
                }
            }
            // An invalid image will throw an OutOfMemoryException
            // exception
            catch (OutOfMemoryException)
            {
                throw new InvalidOperationException("'"	+ m_wpt.ThumbSource + "' is not a valid image file.");
            }

            if(ret)
            {
                setupButtons();
            }
            DlgPhotoManager.sync(false);
            this.BringToFront();

            return ret;
        }