Giter VIP home page Giter VIP logo

Comments (14)

kwhopper avatar kwhopper commented on June 12, 2024 2

Your usage isn't quite right. The sample usage with XmpMetaFactory.Parse expects the input to contain only XMP text. In this case, you're giving it the entire JPEG as the input. XmpMetaFactory doesn't know how to parse through a JPEG file looking for embedded XMP by itself; that's what MetadataExtractor provides. :)

Give this a try and see if you get better results (you'll need 'using MetadataExtractor;' at the top):

using (var stream = File.OpenRead(fullpath))
{
    var dirs = ImageMetadataReader.ReadMetadata(stream);

    var xmpDir = dirs.OfType<XmpDirectory>().FirstOrDefault();
    if (xmpDir?.XmpMeta != null)
    {
        foreach (var property in xmpDir.XmpMeta.Properties)
            Console.WriteLine($"Path={property.Path} Namespace={property.Namespace} Value={property.Value}");
    }
}

from xmp-core-dotnet.

drewnoakes avatar drewnoakes commented on June 12, 2024 1

That should work, though it round-trips the XMP data through an object model, so the XML string you end up with might not exactly match that which was in the file. I believe it should preserve all the data, so should be fine for most use cases.

from xmp-core-dotnet.

kwhopper avatar kwhopper commented on June 12, 2024

Do you have an image we can test with? There are some Encoding limitations with .NET Standard 1.0 but I'd like to look at your file if possible. Thanks

from xmp-core-dotnet.

GilesTT avatar GilesTT commented on June 12, 2024

Thanks for the reply, here is an image:

(Ive actually been using the MetadataExtractor library, - but I think that uses this XMP-core-dotnet (which I updated to the latest version) and it is the XMP - Region Name tag I was after. Thanks.

from xmp-core-dotnet.

kwhopper avatar kwhopper commented on June 12, 2024

I'm able to read the XMP with the full .NET framework version but will try to setup a .NET Core test also. What code are you using to try and parse this, and on what platform? Thanks

from xmp-core-dotnet.

GilesTT avatar GilesTT commented on June 12, 2024

I'm using: Microsoft Visual Studio Community 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework Version 4.6.01055
Visual C# 2015
OS : Microsoft Windows 7 Professional Version 6.1.7601 Service Pack 1 Build 7601

XmpCore v5.1.3 (Downloaded via NuGet)

Code is:
using XmpCore;
using System.IO;
...
IXmpMeta xmp;
using (var stream = File.OpenRead(FilenameTextBox.Text))
xmp = XmpMetaFactory.Parse(stream); //****** Throws Exception here.

foreach (var property in xmp.Properties)
Console.WriteLine($"Path={property.Path} Namespace={property.Namespace} Value={property.Value}");

Thanks.

from xmp-core-dotnet.

kwhopper avatar kwhopper commented on June 12, 2024
  • fixed a code typo in the previous comment

from xmp-core-dotnet.

GilesTT avatar GilesTT commented on June 12, 2024

Thank you so much, that works great.

from xmp-core-dotnet.

SimonKravis avatar SimonKravis commented on June 12, 2024

Had this problem (UTF-16 not supported encoding ) tried code suggested by kwhopper but get error "Type or Namespace XmpDirectory not found" at line
var xmpDir = dirs.OfType<XmpDirectory>().FirstOrDefault();

and line
if (xmpDir?.XmpMeta != null)

gives syntax error ":" expected after xmpDir?

usings are as follows:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MetadataExtractor; using Global; using XmpCore; using System.IO;

from xmp-core-dotnet.

SimonKravis avatar SimonKravis commented on June 12, 2024

After posting I find the answer to both problems:

                foreach (var directory in directories)
                {
                    if (directory.Name == "XMP")
                    {
                        IXmpMeta xmp;                     
                        using (var stream = File.OpenRead(file))
                        {
                            var dirs = ImageMetadataReader.ReadMetadata(stream);
                            var xmpDir = dirs.OfType<MetadataExtractor.Formats.Xmp.XmpDirectory>().FirstOrDefault();
                            if (xmpDir.XmpMeta != null)
                            {
                                foreach (var property in xmpDir.XmpMeta.Properties)
                                    txtMetaData.Text +=  "XMP Field \t" + property.Path + "\t" + property.Value + "\r\n";
                            }
                        }                       
                    }

from xmp-core-dotnet.

SimonKravis avatar SimonKravis commented on June 12, 2024

I get error "Error processing XMP data: Unsupported Encoding" for one particular JPEG file with the above code with xmpDir .XmpMeta = null, but Exiftool shows many XMP fields present. Any idea what the problem might be?

from xmp-core-dotnet.

drewnoakes avatar drewnoakes commented on June 12, 2024

@SimonKravis your issue was fixed in drewnoakes/metadata-extractor-dotnet#154.

from xmp-core-dotnet.

Beckero84 avatar Beckero84 commented on June 12, 2024

I'm having the same problem as GilesTT, so I stumbled on this page.

Looks like I would need a combination of XMPCore and MetadataExtractor... I simply want to extract the entire XMP xml (as a string/XDocument/...) from a given image file.

Any idea if (and how) this is possible with these packages?

from xmp-core-dotnet.

Beckero84 avatar Beckero84 commented on June 12, 2024

I'm having the same problem as GilesTT, so I stumbled on this page.

Looks like I would need a combination of XMPCore and MetadataExtractor... I simply want to extract the entire XMP xml (as a string/XDocument/...) from a given image file.

Any idea if (and how) this is possible with these packages?

Think I found it.

`
XmpDirectory xmpDirectory = ImageMetadataReader.ReadMetadata(fileName).OfType().FirstOrDefault();

        if (xmpDirectory == null)
        {
            return null;
        }

        string xml = XmpMetaFactory.SerializeToString(xmpDirectory.XmpMeta, new SerializeOptions { OmitPacketWrapper = true });

        //Remove the BOM if necessary
        int index = xml.IndexOf('<');
        if (index > 0)
        {
            xml = xml.Substring(index, xml.Length - index);
        }

        var document = new XmlDocument();
        document.LoadXml(xml);`

Apparently with the test file I used, the serialized string starts with a BOM, so therefore the substring.

from xmp-core-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.