Browse Source

ParseRating -> TryParseRating

main
Colin McMillen 12 months ago
parent
commit
cb01d1dbea
  1. 16
      Program.cs

16
Program.cs

@ -166,7 +166,7 @@ public class Photo {
public async void Load() {
image = await Image.LoadAsync<Rgba32>(File);
ParseRating(image);
TryParseRating(image.Metadata.XmpProfile, out Rating);
ExifProfile? exifs = image.Metadata.ExifProfile;
if (exifs != null) {
// FIXME: handle Orientation
@ -240,27 +240,27 @@ public class Photo {
}
}
private void ParseRating(Image image) {
XmpProfile? xmp = image.Metadata.XmpProfile;
private bool TryParseRating(XmpProfile? xmp, out int rating) {
rating = 0;
if (xmp == null) {
return;
return false;
}
XDocument? doc = xmp.GetDocument();
if (doc == null) {
return;
return false;
}
XElement? root = doc.Root;
if (root == null) {
return;
return false;
}
foreach (XElement elt in root.Descendants()) {
if (elt.Name == "{http://ns.adobe.com/xap/1.0/}Rating") {
int rating;
if (int.TryParse(elt.Value, out rating)) {
Rating = rating;
return true;
}
}
}
return false;
}
public Texture Texture() {

Loading…
Cancel
Save