static void imgStyle(ref Image img, ImageSelection image) { var directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(image.getPath()); foreach (var directory in directories) { foreach (var tag in directory.Tags) { if (tag.Name == "Orientation" && directory.Name == "Exif IFD0") { OrientationChecking.rotateChecking(ref img, tag.Description); break; } } if (directory.HasError) { foreach (var error in directory.Errors) { Console.WriteLine($"ERROR: {error}"); } } } img.SetHorizontalAlignment(HorizontalAlignment.CENTER); img.SetAutoScale(true); }
public static void getDim(ref ImageSelection image) { var directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(image.getPath()); bool foundWidth = false; bool foundHeight = false; string descriptionWidth = ""; string descriptionHeight = ""; foreach (var directory in directories) { foreach (var tag in directory.Tags) { if (!foundWidth && (tag.Name == "Image Width") && (directory.Name == "JPEG" || directory.Name == "JPG" || directory.Name.Contains("JPG") || directory.Name.Contains("JPEG") || directory.Name.Contains("PNG") || directory.Name.Contains("JFIF") || directory.Name.Contains("BMP") || directory.Name.Contains("TIF") || directory.Name.Contains("TIFF") || directory.Name.Contains("GIF"))) { descriptionWidth = tag.Description; foundWidth = true; } if (!foundHeight && (tag.Name == "Image Height") && (directory.Name == "JPEG" || directory.Name == "JPG" || directory.Name.Contains("JPG") || directory.Name.Contains("JPEG") || directory.Name.Contains("PNG") || directory.Name.Contains("JFIF") || directory.Name.Contains("BMP") || directory.Name.Contains("TIF") || directory.Name.Contains("TIFF") || directory.Name.Contains("GIF"))) { descriptionHeight = tag.Description; foundHeight = true; } if (foundHeight && foundWidth) { break; } } if (directory.HasError) { foreach (var error in directory.Errors) { Console.WriteLine($"ERROR: {error}"); } } if (foundHeight && foundWidth) { break; } } Regex rx = new Regex(@"[0-9]{1,6}", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (rx.IsMatch(descriptionWidth)) { image.setWidth(int.Parse(rx.Match(descriptionWidth).Value)); } if (rx.IsMatch(descriptionHeight)) { image.setHeight(int.Parse(rx.Match(descriptionHeight).Value)); } if (image.getHeight() >= image.getWidth()) { image.format = "portrait"; } else { image.format = "landscape"; } Console.WriteLine(image.ToString() + " " + image.getWidth() + "(width)x" + image.getHeight() + "(height) " + image.format); }