private KeyValuePair <String, String> ExtractExifDataByLabel(string label, ExifTagCollection exifData)
 {
     return(new KeyValuePair <string, string>(label,
                                              exifData.Where(x => x.Label == label)
                                              .Select(x => x.Raw)
                                              .FirstOrDefault()));
 }
        public ActionResult Index(InfoImageMV model)
        {
            var infoImage = new ExifTagCollection(model.ImagePath);

            foreach (ExifTag elm in infoImage)
            {
                model.ResultImage.Add(elm);
            }
            MatLabConfig mark = new MatLabConfig();

            mark.MatlabObj.Execute("clc; clear");
            mark.MatlabObj.Execute("cd " + mark.matlabFuncPath);
            ImageInfoMark item = new ImageInfoMark();

            //model.ImagePath = mark.matlabDataPath + "\\THMILKImages\\10000315_SM000736_C000117994_1456718517808.jpg";
            item = mark.ImageReal(model.ImagePath);
            model.ListItem.Add(item);
            item = mark.ItemExistImage(model.ImagePath);
            model.ListItem.Add(item);
            mark.MatlabObj.Quit();
            //List<ObjParamSP> listParam = new List<ObjParamSP>();
            //listParam.Add(new ObjParamSP() { Key = "CommandType", Value = results.CommandType });
            //listParam.Add(new ObjParamSP() { Key = "CommandId", Value = results.CommandId });
            //listParam.Add(new ObjParamSP() { Key = "CommandAction", Value = results.CommandAction });
            //listParam.Add(new ObjParamSP() { Key = "ResultData", Value = deserializer.Serialize(results.Data) });
            //listParam.Add(new ObjParamSP() { Key = "MessStatus", Value = results.Status });
            //listParam.Add(new ObjParamSP() { Key = "Topic", Value = e.Topic });
            //listParam.Add(new ObjParamSP() { Key = "CreateTime", Value = DateTime.Now });
            //var sdsdsd = Utility.Helper.QueryStoredProcedure("LogMessages", listParam);
            return(View(model));
        }
示例#3
0
        public static void ExtractMetaData(tblImage image)
        {
            var path       = string.Format("~/Images/Albums/{0}", image.tblAlbum.ALB_Name);
            var mappedPath = System.Web.Hosting.HostingEnvironment.MapPath(path);
            var imagePath  = Path.Combine(mappedPath, Path.GetFileName(image.IMG_Name));


            //string filePath = string.Format("~/Images/Albums/{0}", image.tblAlbum.ALB_Name);
            //string relativePath = string.Format("Images/Albums/{0}/{1}", ddlAlbums, masterimage.FileName);
            // string path = Path.Combine(Server.MapPath(filePath), Path.GetFileName(masterimage.FileName));



            ExifTagCollection _exif = new ExifTagCollection(imagePath);

            foreach (ExifTag tag in _exif)
            {
                tblMetaType metaType = new tblMetaType();
                metaType.MTT_IDPkey = tag.Id;;
                metaType.MTT_Name   = tag.FieldName;
                tblMetaData meta = new tblMetaData();
                meta.MTD_Value  = tag.Value.Length > 500 ? "" : tag.Value;
                meta.MTT_IDFkey = tag.Id;
                meta.tblImage   = image;
                image.tblMetaDatas.Add(meta);
            }
        }
 private KeyValuePair<String, String> ExtractExifDataByLabel(string label, ExifTagCollection exifData)
 {
     return new KeyValuePair<string, string>(label,
                                             exifData.Where(x => x.Label == label)
                                                       .Select(x => x.Raw)
                                                       .FirstOrDefault());
 }
示例#5
0
        public DateTime GetDateTaken()
        {
            DateTime          formattedDateTaken = DateTime.MinValue;
            ExifTagCollection exif;

            try
            {
                exif = new ExifTagCollection(_photoInfo.FullName);

                var dateTaken = exif[36867];

                bool success = DateTime.TryParse(dateTaken.Value, out formattedDateTaken);

                if (!success)
                {
                    try
                    {
                        formattedDateTaken = ConvertDate(dateTaken.Value);
                    }
                    catch (Exception)
                    {
                        //throw
                    }
                }
            }
            catch (Exception ex)
            {
                //var x = 1;
                //var y = GetDateTakenFromImage(_photoInfo.FullName);
                //throw;
            }

            return(formattedDateTaken);
        }
        // note that we also have EXIF metadata that can be extracted

        // this is problematic since it ties this class to ScaledImage
        //
        public void AddThumbs(List <Thumbnail> thumbsToGenerate)
        {
            // read metadata and if the orientation is 90 cw or 90 ccw, perform the rotation
            // todo, refactor the tag processing into its own function, as AddThumbs should do just that
            Image imgPhotoToRotate = Image.FromFile(Filename);

            var exif = new ExifTagCollection(Filename);

            // todo, use other fields such as artist and exposure data and to populate related fields?

            var PropertyItems = imgPhotoToRotate.PropertyItems;
            // to
            var orientation = exif.Where(ex => ex.FieldName == "Orientation").FirstOrDefault();

            // if no orinentation property exists, then the camera figured out the correct height and width (eg cell phone cam, with accelerometer)
            // or if the orientation is reported as "normal" no need to rotate
            if (orientation != null &&
                orientation.Value != "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.")
            {
                int angle = 0;
                if (orientation.Value == "The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.")
                {
                    // rotate 90 degrees, this seems to be most common with camera that sense the orientation but somehow
                    // keep width to be the larger dimension and height the smaller, as in a point and shoot
                    angle = 90;
                }
                else if (orientation.Value == "The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.")
                {
                    angle = 270;
                }
                Image imgPhoto = ImageProcessor.RotateImage(imgPhotoToRotate, angle);
                foreach (var pi in imgPhotoToRotate.PropertyItems)
                {
                    // todo, create symbolic constants for Id values
                    // copy properties, except for orientation, which we set to "normal"
                    // i.e. "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side."
                    if (pi.Id == 0x112)
                    {
                        ushort normal = 1;
                        pi.Value = BitConverter.GetBytes(normal);
                    }
                    imgPhoto.SetPropertyItem(pi);
                }
                imgPhotoToRotate.Dispose();
                imgPhoto.Save(Filename, ImageFormat.Jpeg);
            }

            // here I want to set the orientation to "1" or normal after rotating it
            // imgPhotoToRotate.SetPropertyItem(PropertyItems[0]);

            //

            // get the standard thumbs
            foreach (var th in thumbsToGenerate)
            {
                ScaledImage si = new ScaledImage(th, this);
                si.Process();
            }
        }
示例#7
0
        public static string extractexif(string path1)
        {
            string          wkt     = "POINT(";
            string          lon     = "";
            string          lat     = "";
            string          tmp1    = "";
            string          pattern = "([0-9]+|[,0-9]+)";
            Regex           rx      = new Regex(pattern);
            MatchCollection mh;

            try
            {
                ExifTagCollection exif = new ExifTagCollection(path1);
                foreach (ExifTag tag in exif)
                {
                    if (tag.FieldName.Equals("GPSLongitude", StringComparison.InvariantCultureIgnoreCase))
                    {
                        tmp1 = tag.Value.Replace("°", "").Replace("'", "").Replace("\"", "");
                        mh   = rx.Matches(tmp1);
                        lon  = compare(mh);
                    }
                    if (tag.FieldName.Equals("GPSLatitude", StringComparison.InvariantCultureIgnoreCase))
                    {
                        tmp1 = tag.Value.Replace("°", "").Replace("'", "").Replace("\"", "");
                        mh   = rx.Matches(tmp1);
                        lat  = compare(mh);
                    }
                }
                if (lon != null || lat != null)
                {
                    if (lon != "" || lat != "")
                    {
                        wkt += lon + " " + lat + ")";
                        return(wkt);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception x)
            {
                throw new Exception("Err1", x);
            }
        }
        public static void PrintExifTags(ExifTagCollection exif)
        {
            var tags = exif.GroupBy(ex => ex.TagSpace).Select(g => new { Category = g.Key, ExifTag = g });

            foreach (var tag in tags)
            {
                Console.WriteLine($"--- {tag.Category} ---");
                foreach (var exifTag in tag.ExifTag)
                {
                    Console.WriteLine($"{exifTag.Label} {exifTag.Raw}");
                }

                Console.WriteLine("\n");
            }
        }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ExifTagCollection exif = new ExifTagCollection(ofd.FileName);

                ExifTag tag = exif[2];
                Console.Out.WriteLine(tag);
                //Latitude (GPSLatitude) = 22° 47' 35,35"
            }
        }
示例#10
0
        public ExifWrapper(ExifTagCollection photoExif)
        {
            if (photoExif == null) throw new ArgumentNullException("photoExif");

            Model = GetExifData(photoExif, "Model");
            Exposure = GetExifData(photoExif, "ExposureTime");
            Aperture = GetExifData(photoExif, "FNumber");
            IsoSpeed = GetExifData(photoExif, "ISO");
            FocalLength = GetExifData(photoExif, "FocalLength");
            LensDetails = GetExifData(photoExif, "Lens");

            // Example format - 2012:05:26 13:25:18

            DateCreated = Convert.ToDateTime(GetExifData(photoExif, "DateCreated").Replace(':', '-'));
            TimeCreated = Convert.ToDateTime(GetExifData(photoExif, "TimeCreated"));
            CreatedDateTime = Convert.ToDateTime(String.Format("{0} {1}", DateCreated.ToShortDateString(), TimeCreated.ToShortTimeString()));
        }
        private void imageView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (e.IsSelected)
            {
                infoPanel.Items.Clear();
                ListViewItem selected = e.Item;
                Bitmap image = selected.Tag as Bitmap;

                ExifTagCollection tags = new ExifTagCollection(image);
                foreach (ExifTag tag in tags)
                {
                    var item = new ListViewItem(tag.FieldName);
                    item.SubItems.Add(tag.Value);
                    infoPanel.Items.Add(item);
                }
            }
        }
        private void imageView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (e.IsSelected)
            {
                infoPanel.Items.Clear();
                ListViewItem selected = e.Item;
                Bitmap       image    = selected.Tag as Bitmap;

                ExifTagCollection tags = new ExifTagCollection(image);
                foreach (ExifTag tag in tags)
                {
                    var item = new ListViewItem(tag.FieldName);
                    item.SubItems.Add(tag.Value);
                    infoPanel.Items.Add(item);
                }
            }
        }
示例#13
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ItemInfo info = ((Item)((ListBox)sender).SelectedItem).itemInfo;

            if (canBeDisplayed(info.x.fullPath))
            {
                try {
                    ExifTagCollection exif = new ExifTagCollection(info.x.fullPath);
                    leftTaken.Text = exif.getValue("DateTimeOriginal");
                    leftPBox.Load(info.x.fullPath);
                    DirInfo di = dirInfo[System.IO.Path.GetDirectoryName(info.x.fullPath)];
                    leftDupPercInFolder.Text = String.Format("{0} / {1} ", di.dupCount, di.totalFiles);
                } catch (Exception ex)
                {
                    button1.Parent.Text = ex.Message;
                }
            }
            else
            {
                leftPBox.Image = null;
            }
            if (canBeDisplayed(info.y.fullPath))
            {
                try
                {
                    ExifTagCollection exif = new ExifTagCollection(info.y.fullPath);
                    rightTaken.Text = exif.getValue("DateTimeOriginal");
                    rightPBox.Load(info.y.fullPath);
                    DirInfo di = dirInfo[System.IO.Path.GetDirectoryName(info.y.fullPath)];
                    rightDupPercInFolder.Text = String.Format("{0} / {1} ", di.dupCount, di.totalFiles);
                }
                catch (Exception ex)
                {
                    button1.Parent.Text = ex.Message;
                }
            }
            else
            {
                rightPBox.Image = null;
            }
            leftPath.Text = info.x.fullPath.Substring(path.Length);
            leftsize.Text = info.x.size.ToString();

            rightPath.Text = info.y.fullPath.Substring(path.Length);
            rightSize.Text = info.y.size.ToString();
        }
示例#14
0
        public void ReadExif(ExifTagCollection exif)
        {
            if (exif == null)
            {
                return;
            }

            if (exif["GPSLatitude"] != null)
            {
                try
                {
                    string lat = exif["GPSLatitude"].Value;
                    this.Latitude = FromGMS(lat);

                    if (exif["GPSLatitudeRef"] != null && exif["GPSLatitudeRef"].Value.ToLower().StartsWith("south"))
                    {
                        this.Latitude = -this.Latitude;
                    }
                }
                catch { }
            }

            if (exif["GPSLongitude"] != null)
            {
                try
                {
                    string lng = exif["GPSLongitude"].Value;
                    this.Longitute = FromGMS(lng);

                    if (exif["GPSLongitudeRef"] != null && exif["GPSLongitudeRef"].Value.ToLower().StartsWith("west"))
                    {
                        this.Longitute = -this.Longitute;
                    }
                }
                catch { }
            }

            if (exif["DateTimeOriginal"] != null)
            {
                DateTime t;
                if (DateTime.TryParseExact(exif["DateTimeOriginal"].Value, "yyyy:MM:dd HH:mm:ss", CultureInfo.CurrentCulture, DateTimeStyles.None, out t))
                {
                    this.DateTimeOriginal = t;
                }
            }
        }
示例#15
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                pictureBox.Image = Image.FromFile(ofd.FileName);

                listExif.Items.Clear();

                _exif = new ExifTagCollection(ofd.FileName);

                foreach (ExifTag tag in _exif)
                    AddTagToList(tag);
            }
        }
        public void PhotosGetExifTest()
        {
            ExifTagCollection tags = Instance.PhotosGetExif("4268023123");

            Assert.IsNotNull(tags, "ExifTagCollection should not be null.");

            Assert.IsTrue(tags.Count > 20, "More than twenty parts of EXIF data should be returned.");

            Assert.AreEqual("IFD0", tags[0].TagSpace, "First tags TagSpace is not set correctly.");
            Assert.AreEqual(0, tags[0].TagSpaceId, "First tags TagSpaceId is not set correctly.");
            Assert.AreEqual("ImageDescription", tags[0].Tag, "First tags Tag is not set correctly.");
            Assert.AreEqual("Image Description", tags[0].Label, "First tags Label is not set correctly.");
            Assert.AreEqual(
                "It scares me sometimes how much some of my handwriting reminds me of Dad's " +
                "- in this photo there is one 5 that especially reminds me of his handwriting.",
                tags[0].Raw, "First tags RAW is not correct.");
            Assert.IsNull(tags[0].Clean, "First tags Clean should be null.");
        }
        public void PhotosGetExifIPhoneTest()
        {
            bool bFound            = false;
            ExifTagCollection tags = Instance.PhotosGetExif("5899928191");

            Assert.AreEqual("Apple iPhone 4", tags.Camera, "Camera property should be set correctly.");

            foreach (ExifTag tag in tags)
            {
                if (tag.Tag == "Model")
                {
                    Assert.IsTrue(tag.Raw == "iPhone 4", "Model tag is not 'iPhone 4'");
                    bFound = true;
                    break;
                }
            }
            Assert.IsTrue(bFound, "Model tag not found.");
        }
示例#18
0
        public static byte[] AutoRotate(byte[] imageBytes, ImageMetadata metadata = null)
        {
            try
            {
                using (System.Drawing.Bitmap from = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(new MemoryStream(imageBytes)))
                {
                    var exif = new ExifTagCollection(from);
                    if (metadata != null)
                    {
                        metadata.ReadExif(exif);
                    }

                    if (exif["Orientation"] != null)
                    {
                        RotateFlipType flip = OrientationToFlipType(exif["Orientation"].Value);

                        if (flip != RotateFlipType.RotateNoneFlipNone) // don't flip of orientation is correct
                        {
                            from.RotateFlip(flip);
                            try
                            {
                                //exif.setTag(0x112, "1"); // Optional: reset orientation tag
                            }
                            catch { }

                            MemoryStream ms = new MemoryStream();
                            from.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            return(Stream2Bytes(ms));
                        }
                        else
                        {
                            return(imageBytes);
                        }
                    }
                    else
                    {
                        return(imageBytes);
                    }
                }
            }

            catch { }
            return(null);
        }
示例#19
0
        public void PhotosGetExifTest()
        {
            Flickr f = Instance;

            ExifTagCollection tags = f.PhotosGetExif("4268023123");

            Console.WriteLine(f.LastResponse);

            Assert.IsNotNull(tags, "ExifTagCollection should not be null.");

            Assert.IsTrue(tags.Count > 20, "More than twenty parts of EXIF data should be returned.");

            Assert.AreEqual("IFD0", tags[0].TagSpace, "First tags TagSpace is not set correctly.");
            Assert.AreEqual(0, tags[0].TagSpaceId, "First tags TagSpaceId is not set correctly.");
            Assert.AreEqual("Compression", tags[0].Tag, "First tags Tag is not set correctly.");
            Assert.AreEqual("Compression", tags[0].Label, "First tags Label is not set correctly.");
            Assert.AreEqual("JPEG (old-style)", tags[0].Raw, "First tags RAW is not correct.");
            Assert.IsNull(tags[0].Clean, "First tags Clean should be null.");
        }
示例#20
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                pictureBox.Image = Image.FromFile(ofd.FileName);

                listExif.Items.Clear();

                _exif = new ExifTagCollection(ofd.FileName);

                foreach (ExifTag tag in _exif)
                {
                    AddTagToList(tag);
                }
            }
        }
示例#21
0
        public ActionResult XuLy(InfoImageMV model)
        {
            var infoImage = new ExifTagCollection(model.ImagePath);

            foreach (ExifTag elm in infoImage)
            {
                model.ResultImage.Add(elm);
            }
            MatLabConfig mark = new MatLabConfig();

            mark.MatlabObj.Execute("clc; clear");
            mark.MatlabObj.Execute("cd " + mark.matlabFuncPath);
            ImageInfoMark item = new ImageInfoMark();

            //model.ImagePath = mark.matlabDataPath + "\\THMILKImages\\10000315_SM000736_C000117994_1456718517808.jpg";
            item = mark.ImageReal(model.ImagePath);
            model.ListItem.Add(item);
            item = mark.ItemExistImage(model.ImagePath);
            model.ListItem.Add(item);
            mark.MatlabObj.Quit();
            return(View());
        }
示例#22
0
        public static byte[] GetMetaDataByteStream(string imagePath)
        {
            ExifTagCollection           _exif = new ExifTagCollection(imagePath);
            Dictionary <string, string> meta  = new Dictionary <string, string>();

            foreach (ExifTag tag in _exif)
            {
                meta.Add(tag.FieldName, tag.Value.Length > 500 ? "" : tag.Value);
            }

            string jsonstring = JsonConvert.SerializeObject(meta);

            //BinaryFormatter bf = new BinaryFormatter();
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    bf.Serialize(ms, jsonstring);
            //    return ms.ToArray();
            //}

            string someString = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(jsonstring));

            return(Encoding.ASCII.GetBytes(jsonstring));
        }
        /// <summary>
        /// Generates all the images into the specified folder. The names
        /// are the same for feh can reload them without issue. 
        /// </summary>
        private static void UpdateImages()
        {
            GenerateDateImage();

            Console.WriteLine(DateTime.Now.ToLongTimeString());

            var allImages = System.IO.Directory.GetFiles(Properties.Settings.Default.ImageSourcePath, "*.jpg", SearchOption.AllDirectories);
            var random = new Random();

            for (int i = 0; i < Properties.Settings.Default.ImagesToGenerate; i++)
            {
                var randomImage = allImages[random.Next(allImages.Length)];
                Console.WriteLine(DateTime.Now.ToLongTimeString());
                Console.WriteLine(randomImage);
                try
                {

                    using (Image image = Bitmap.FromFile(randomImage))
                    {
                        ExifTagCollection exif = new ExifTagCollection(randomImage);
                        if (exif[274] != null)
                        {
                            Console.Out.WriteLine(exif[274]);
                            switch (exif[274].Value)
                            {
                                case "1":
                                    break;//) transform="";;
                                case "2":
                                    image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                    break;//) transform="-flip horizontal";;
                                case "3":
                                    image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                                    break;//) transform="-rotate 180";;
                                case "4":
                                    image.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                    break;//) transform="-flip vertical";;
                                case "5":
                                    image.RotateFlip(RotateFlipType.Rotate90FlipY);
                                    break;//) transform="-transpose";;
                                case "6":
                                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                                    break;//) transform="-rotate 90";;
                                case "7":
                                    image.RotateFlip(RotateFlipType.Rotate270FlipY);
                                    break;//) transform="-transverse";;
                                case "8":
                                    image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                                    break;//) transform="-rotate 270";;

                                default:
                                    break;
                            }
                        }

                        using (Bitmap resized = ResizeBitmap((Bitmap)image, Properties.Settings.Default.ImageWidth, Properties.Settings.Default.ImageHeight))
                        {
                            resized.SaveJpeg(Properties.Settings.Default.ImageDestinationPath + "image" + i.ToString() + ".jpg", 100L);
                        }
                    }
                }
                catch (Exception)
                {

                    //throw;
                }

            }
        }
示例#24
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                tssLabel.Text = ofd.FileName;
                bool bRes = false;
                picPreview.Image = Image.FromFile(ofd.FileName);
                listExif.Items.Clear();
                _exif = new ExifTagCollection(ofd.FileName);

                foreach (ExifTag tag in _exif)
                {
                    if (tag.Id == 1)
                        bRes = true;
                    AddTagToList(tag);
                }
                if (bRes == true)
                {
                    ExifTag NSTag = _exif[1];
                    ExifTag LatTag = _exif[2];
                    ExifTag EWTag = _exif[3];
                    ExifTag LongTag = _exif[4];
                    string lat = LatTag.Value.ToString();
                    string[] lat_split = lat.Split(' ');
                    if (lat != "")
                    {
                        StringBuilder queryAddress = new StringBuilder();
                        queryAddress.Append("http://maps.googleapis.com/maps/api/staticmap?center=");
                        string latNum1 = Regex.Replace(lat_split[0], "[^.0-9]", "");
                        string latNum2 = Regex.Replace(lat_split[1], "[^.0-9]", "");
                        string latNum3 = Regex.Replace(lat_split[2], "[^.0-9]", "");
                        double latVal1 = double.Parse(latNum1);
                        double latVal2 = double.Parse(latNum2);
                        double latVal3 = double.Parse(latNum3);
                        double lat_value = latVal1 + (latVal2 / 60) + (latVal3 / 3600);
                        if (NSTag.Value.ToString().Substring(0, 5) == "South")
                        {
                            queryAddress.Append("-");
                        }
                        queryAddress.Append(lat_value);

                        string lon = LongTag.Value.ToString();
                        string[] lon_split = lon.Split(' ');
                        string lonNum1 = Regex.Replace(lon_split[0], "[^.0-9]", "");
                        string lonNum2 = Regex.Replace(lon_split[1], "[^.0-9]", "");
                        string lonNum3 = Regex.Replace(lon_split[2], "[^.0-9]", "");
                        double lonVal1 = double.Parse(lonNum1);
                        double lonVal2 = double.Parse(lonNum2);
                        double lonVal3 = double.Parse(lonNum3);
                        double lon_value = lonVal1 + (lonVal2 / 60) + (lonVal3 / 3600);
                        queryAddress.Append(",");

                        if (EWTag.Value.ToString().Substring(0, 4) == "west")
                        {
                            queryAddress.Append("-");
                        }
                        queryAddress.Append(lon_value);
                        queryAddress.Append("&zoom=10&size=400x400&maptype=terrain&sensor=true&key=ABQIAAAAaHAby4XeLCIadFkAUW4vmRSkJGe9mG57rOapogjk9M-sm4TzXxR2I7bi2Qkj-opZe16CdmDs7_dNrQ");

                        webBrowser1.Navigate(queryAddress.ToString());
                    }
                }
            }
        }
示例#25
0
        // note that we also have EXIF metadata that can be extracted

        // this is problematic since it ties this class to ScaledImage
        // 
        public void AddThumbs(List<Thumbnail> thumbsToGenerate)
        {
            // read metadata and if the orientation is 90 cw or 90 ccw, perform the rotation
            // todo, refactor the tag processing into its own function, as AddThumbs should do just that
            Image imgPhotoToRotate = Image.FromFile(Filename);

            var exif = new ExifTagCollection(Filename);

            // todo, use other fields such as artist and exposure data and to populate related fields?

            var PropertyItems = imgPhotoToRotate.PropertyItems;
            // to
            var orientation = exif.Where(ex => ex.FieldName == "Orientation").FirstOrDefault();
            // if no orinentation property exists, then the camera figured out the correct height and width (eg cell phone cam, with accelerometer)
            // or if the orientation is reported as "normal" no need to rotate
            if (orientation != null &&
                orientation.Value != "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.")
            {
                int angle = 0;
                if (orientation.Value == "The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.")
                {
                    // rotate 90 degrees, this seems to be most common with camera that sense the orientation but somehow
                    // keep width to be the larger dimension and height the smaller, as in a point and shoot
                    angle = 90;
                }
                else if (orientation.Value ==  "The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.")
                {
                    angle = 270;
                }
                Image imgPhoto = ImageProcessor.RotateImage(imgPhotoToRotate, angle);
                foreach(var pi in imgPhotoToRotate.PropertyItems)
                {
                    // todo, create symbolic constants for Id values
                    // copy properties, except for orientation, which we set to "normal"
                    // i.e. "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side."
                    if (pi.Id == 0x112)
                    {
                        ushort normal = 1;
                        pi.Value = BitConverter.GetBytes(normal);
                    }
                    imgPhoto.SetPropertyItem(pi);
                }
                imgPhotoToRotate.Dispose();
                imgPhoto.Save(Filename, ImageFormat.Jpeg);

            }

            // here I want to set the orientation to "1" or normal after rotating it
            // imgPhotoToRotate.SetPropertyItem(PropertyItems[0]);

            //

            // get the standard thumbs
            foreach (var th in thumbsToGenerate)
            {
                ScaledImage si = new ScaledImage(th, this);
                si.Process();
            }
        }
示例#26
0
 private string GetExifData(ExifTagCollection photoExif, string tagName)
 {
     ExifTag exifItem = photoExif.FirstOrDefault(x => x.Tag == tagName);
     if (exifItem != null) return exifItem.Raw;
     return String.Empty;
 }
示例#27
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPEG Files (*.jpg)|*.jpg|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ExifTagCollection exif = new ExifTagCollection(ofd.FileName);

                ExifTag tag = exif[2];
                Console.Out.WriteLine(tag);
                //Latitude (GPSLatitude) = 22° 47' 35,35"
            }
        }