0

I am currently downloading images that have been stored as a base 64 string on my database. The issue is that I need to also get the images EXIF data to determine the images orientation. I am wondering if their is a way to get the EXIF data.

The following is my c# code.

 busyMessage.Text = "Loading Tools";
 InvToolSync toolSync = new InvToolSync();
 toolData = await toolSync.GetTools(viewModel.CompanyData.company_id);
 foreach (Tool tool in toolData)
 {
    if (tool.archived == "True")
       continue;

    var lt = new ListTemplate(tool.id, tool.name, ImageSource.FromFile("default_image.png"));

    if (!string.IsNullOrEmpty(tool.photos))
        if (tool.photos.Length % 4 == 0)
            lt.SourceImage = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(tool.photos)));

    listDisplay.Add(lt);
 }

The above code loads the the data required to populate a list item and as you can see I am able I get the image's data url with this code tool.photos. But I cannot seem to figure out how to get the EXIF data. Is their a plugin or some c# code that could get this from a base64 string or even a the byte array?

Thanks.

Hayden Passmore
  • 1,135
  • 2
  • 12
  • 34
  • 2
    There are some Exif nuget packages which seem like they ought to fit the bill, though I doubt you'll find any that do it in base64 form so you'll probably have to convert to a byte array first. – ProgrammingLlama Apr 23 '18 at 05:43

1 Answers1

3

You can use Convert.FromBase64String to get a byte[] of your image data.

With that, you can use MetadataExtractor to access all the metadata from the image, not just Exif:

var directories = ImageMetadataReader.ReadMetadata(
    new MemoryStream(bytes));

foreach (var directory in directories)
foreach (var tag in directory.Tags)
    Console.WriteLine($"{directory.Name} - {tag.Name} = {tag.Description}");

The library is available via NuGet here: https://www.nuget.org/packages/MetadataExtractor/

(I have maintained this project since 2002.)

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742