Пример #1
0
        public override ExifTag Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            string  value = reader.GetString();
            ExifTag tag   = ExifUtils.FindByName(value);

            return((tag != null) ? tag : throw new JsonException());
        }
Пример #2
0
        public void TestFindingExifValue()
        {
            ExifTag expected = ExifTag.Artist;
            ExifTag actual   = ExifUtils.FindByName("Artist");

            Assert.Equal(expected, actual);
        }
        private void PhotoChooserCompleted(object sender, PhotoResult e)
        {
            this.showInProgress = false;
            if (e.TaskResult == TaskResult.OK)
            {
                // Defensive. This should not happen unless maybe someone programmatically saved a 0 length image in
                // the picture gallery which I am not even sure the phone API will allow.
                // Since this.ocrData.PhotoStream will not accept a zero length stream we'll act defensively here.
                if (e.ChosenPhoto.Length > 0)
                {
                    Stream photoStream;

                    // This is the point where we have a photo available.
                    photoStream = e.ChosenPhoto;

                    // Extract the orientation flag from the photo before we do the scaling down.
                    // If the scaling down is performed we'll no longer have the Exif info in the photo stream.
                    ExifUtils exifUtils = new ExifUtils(OcrClientUtils.GetPhotoBits(photoStream));
                    this.ocrData.ExifOrientationFlag = exifUtils.GetOrientationFlag();

                    if (DoLimitPhotoSize)
                    {
                        photoStream = OcrClientUtils.LimitPhotoSize(photoStream, PhotoMaxSizeDiagonal);
                    }

                    // When setting this.ocrData.PhotoStream, the ocrData instance will notify anyone who subscribed
                    // to its PropertyChanged event. One of the subscribers to PropertyChanged will see that
                    // the PhotoStream became available and it will trigger the OCR conversion.
                    this.ocrData.PhotoStream = photoStream;
                }
            }
        }
Пример #4
0
        public void GetTagNames()
        {
            List <string> tags = ExifUtils.GetNames().ToList();

            const string expected = "FaxProfile";
            string       actual   = tags[0];

            Assert.Equal(expected, actual);
        }
Пример #5
0
        /// <summary>
        /// Забираем данные из Exif'а
        /// </summary>
        static DateTime setMetadata(XmlElement el, String path, Boolean isFolder)
        {
            DateTime dt;
            var      targetObj = Path.Combine(path, el.GetAttribute("path2"));

            ImageInfo info;

            if (isFolder)
            {
                dt = Directory.GetCreationTime(targetObj);
            }
            else
            {
                //dt = File.GetCreationTime(targetObj);
                info = ExifUtils.GetExifData(targetObj, true);
                dt   = info.Shot;

                if (!info.FileNameIsUsed && !string.IsNullOrEmpty(info.Caption))
                {
                    el.SetAttribute("title", info.Caption);
                    el.RemoveAttribute("f");
                }
                if (!string.IsNullOrEmpty(info.Description))
                {
                    el.SetAttribute("description", info.Description);
                }

                string shotInfo = info.GetShotCaption(true);
                if (!string.IsNullOrEmpty(shotInfo))
                {
                    el.SetAttribute("shot", shotInfo);
                }

                if (info.Latitude.HasValue)
                {
                    el.SetAttribute("lat", XmlConvert.ToString(info.Latitude.Value));
                    el.SetAttribute("long", XmlConvert.ToString(info.Longitude.Value));
                }
            }

            el.SetAttribute("date", XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Local));

            return(dt);
        }
Пример #6
0
        public SchemaController(ILogger <PreviewController> logger)
        {
            _logger = logger;

            _exifTags = ExifUtils.GetNames().ToList();
            _exifTags.Sort();

            string[] iptcTags = Enum.GetNames(typeof(IptcTag));
            _iptcTags = new List <string>(iptcTags);
            _iptcTags.Remove("Unknown");
            _iptcTags.Sort();

            string[] filtersArray = Enum.GetNames(typeof(FilterType));
            _resizeFilters = new List <string>(filtersArray).ToList();
            _resizeFilters.Remove("Undefined");
            _resizeFilters.Sort();
            _resizeFilters.Insert(0, "Default");

            _fontFamilies = FontFamilies.Select((family) => family.Name).Distinct().ToList();
            _fontFamilies.Sort();
            _fontFamilies.Insert(0, "Default");

            _logger.LogInformation("Loading JSON Schema from: {0}", SchemaLocation);
            string schemaTemplate = System.IO.File.ReadAllText(SchemaLocation);

            _schema = JsonSerializer.Deserialize <JsonSchema>(schemaTemplate);

            Dictionary <string, JsonSchemaProperty> buildProperties = _schema.Properties["build"].Properties;

            buildProperties["resize"].Properties["filter"].Enum = _resizeFilters;

            JsonSchemaProperty metadataProperties = buildProperties["metadata"];

            metadataProperties.Properties["exif"].Items.Properties["tag"].Enum = _exifTags;
            metadataProperties.Properties["iptc"].Items.Properties["tag"].Enum = _iptcTags;

            Dictionary <string, JsonSchemaProperty> montageProperties = _schema.Properties["montages"].Items.Properties;

            montageProperties["font-family"].Enum = _fontFamilies;
        }
Пример #7
0
        private String buildTagList(Image img)
        {
            StringBuilder sb = new StringBuilder();

            foreach (PropertyItem pi in img.PropertyItems)
            {
                try {
                    String tagS = ExifUtils.TagToString(pi.Id, pi.Type, pi.Len, pi.Value);
                    if (tagS != String.Empty)
                    {
                        sb.Append(tagS);
                        sb.AppendLine();
                    }
                }
                catch (Exception)
                {
                    Form dialog1 = new Form2(tag_error + ": " + pi.Id);
                    dialog1.ShowDialog();
                }
            }
            return(sb.ToString());
        }
Пример #8
0
        static XDocument getFileList(string path, Metadata meta)
        {
            double    timeShift = meta.TimeShift ?? 0;
            XElement  root;
            XDocument res = new XDocument(root = new XElement("photos"));

            //XmlDocument res = new XmlDocument();
            //XmlElement root = (XmlElement)res.AppendChild(res.CreateElement("photos"));

            Regex regTypedName = new Regex(@"^(?'name'\w{1,}.+)_(?'stype'pub|pup|thumb)\.jpe?g$",
                                           RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            Regex regMainName = new Regex(@"^(?'name'\w{1,}.+)\.jpe?g$",
                                          RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            Dictionary <string, XElement> processed = new Dictionary <string, XElement>(StringComparer.OrdinalIgnoreCase);

            foreach (string f in Directory.EnumerateFiles(path, "*.jpg", SearchOption.TopDirectoryOnly).Union(Directory.EnumerateFiles(path, "*.jpeg", SearchOption.TopDirectoryOnly)))
            {
                string name = Path.GetFileName(f);

                NameType nt = NameType.Main;
                string   baseName;
                Match    m = regTypedName.Match(name);
                if (m.Success)
                {
                    baseName = m.Groups["name"].Value;
                    nt       = string.Compare(m.Groups["stype"].Value, "thumb", true) == 0 ? NameType.Thumb:NameType.Pub;
                }
                else
                {
                    m = regMainName.Match(name);
                    if (m.Success)
                    {
                        baseName = m.Groups["name"].Value;
                        nt       = NameType.Main;
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Warning: file {0} isn't recognized", name));
                        continue;
                    }
                }

                XElement fi;
                if (!processed.TryGetValue(baseName, out fi))
                {
                    root.Add(fi = new XElement("f"));
                    processed.Add(baseName, fi);
                }

                switch (nt)
                {
                case NameType.Main:
                    fi.SetAttributeValue("main", name);
                    break;

                case NameType.Thumb:
                    fi.SetAttributeValue("thumb", name);
                    ImageInfo info = ExifUtils.GetExifData(f, true);
                    //Console.WriteLine(ExifUtils.DumpGdiExifTags(f));
                    fi.SetAttributeValue("caption", info.FileNameIsUsed ? baseName:info.Caption);
                    fi.SetAttributeValue("w", info.W.ToString()); fi.SetAttributeValue("h", info.H.ToString());
                    fi.SetAttributeValue("date", info.Shot.AddHours(timeShift).ToString("dd-MMMM-yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture));
                    fi.SetAttributeValue("shot-info", info.GetShotCaption(true));
                    if (info.Latitude.HasValue)
                    {
                        fi.SetAttributeValue("lat", info.Latitude);
                        fi.SetAttributeValue("long", info.Longitude);
                    }

                    break;

                case NameType.Pub:
                    fi.SetAttributeValue("pub", name);
                    break;
                }

                fi.SetAttributeValue("size", ExifUtils.GetSize(f).ToString());
            }


            return(res);
        }
Пример #9
0
        public void TestNotFindingExifValue()
        {
            ExifTag actual = ExifUtils.FindByName("https://www.youtube.com/watch?v=dQw4w9WgXcQ");

            Assert.Null(actual);
        }