Comments (14)
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.
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.
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.
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.
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.
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.
- fixed a code typo in the previous comment
from xmp-core-dotnet.
Thank you so much, that works great.
from xmp-core-dotnet.
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.
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.
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.
@SimonKravis your issue was fixed in drewnoakes/metadata-extractor-dotnet#154.
from xmp-core-dotnet.
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.
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)
- Sign assemblies HOT 6
- Implement Language property for XmpProperty682 HOT 8
- XMP Toolkit SDK - 2016.07 support? HOT 12
- System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name. HOT 15
- Support .NET Core HOT 1
- Set up CI HOT 1
- NuGet package shouldn't depend upon JetBrains.Annotations
- VS2017 / C# 7 support HOT 1
- Nuget package version not matching assembly version HOT 6
- Support .NET 3.5 HOT 1
- Package specification is missing project URL
- How to write only Xmp metadata using Xmp core HOT 3
- Support for UTF-16 and UTF-32? HOT 12
- Support for PCL HOT 6
- I have a MissingMethodException: Method not found: 'System.Xml.XmlReaderSettings.set_MaxCharactersFromEntities' issue HOT 5
- XmpMetaFactory.ParseFromBuffer fails when there is an XML-comment in the input XML buffer HOT 3
- Improve performance of Latin1Converter
- License is not available
- Create Array of Structs HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xmp-core-dotnet.