/// <summary> /// 获取图片信息 /// </summary> /// <param name="path"></param> /// <returns></returns> public static PictureInnerInfo GetInnerInfo(string path) { try { var info = new PictureInnerInfo(); var data = ImageMetadataReader.ReadMetadata(path); for (var i = 0; i < data.Count; i++) { if (data[i].Tags == null || data[i].TagCount == 0) { continue; } for (var j = 0; j < data[i].Tags.Count; j++) { var tag = data[i].Tags[j]; if (!tag.HasName) { continue; } if (tag.Name == info.AuthorName) { info.Author = tag.Description?.Replace("\0x0001", "").Replace("\u0001", "").Trim().Substring(0, 32); } else if (tag.Name == info.Tag1Name) { info.Tag1 = tag.Description; } else if (tag.Name == info.Tag2Name) { info.Tag2 = tag.Description; } else if (tag.Name == info.DescriptionName) { info.Description = tag.Description; } else if (tag.Name == info.TakeTimeName) { info.TakeTime = tag.Description; } } } return(info); } catch (Exception) { } return(null); }
/// <summary> /// 获取图片信息 /// </summary> /// <param name="path"></param> /// <returns></returns> private static PictureInnerInfo GetInnerInfo(string path) { var info = new PictureInnerInfo(); var data = ImageMetadataReader.ReadMetadata(path); for (var i = 0; i < data.Count; i++) { if (data[i].Tags == null || data[i].TagCount == 0) { continue; } for (var j = 0; j < data[i].Tags.Count; j++) { var tag = data[i].Tags[j]; if (!tag.HasName) { continue; } if (tag.Name == info.AuthorName) { info.Author = tag.Description; } else if (tag.Name == info.Tag1Name) { info.Tag1 = tag.Description; } else if (tag.Name == info.Tag2Name) { info.Tag2 = tag.Description; } else if (tag.Name == info.DescriptionName) { info.Description = tag.Description; } else if (tag.Name == info.HeightName) { info.Height = tag.Description.Replace("pixels", "").Trim(); } else if (tag.Name == info.WidthName) { info.Width = tag.Description.Replace("pixels", "").Trim(); } else if (tag.Name == info.ModifyTimeName) { info.ModifyTime = tag.Description; } else if (tag.Name == info.TakeTimeName) { info.TakeTime = tag.Description; } if (!string.IsNullOrWhiteSpace(info.Author) && !string.IsNullOrWhiteSpace(info.Tag1) && !string.IsNullOrWhiteSpace(info.Tag2) && !string.IsNullOrWhiteSpace(info.Description)) { return(info); } } } return(info); }