by
8,582 17
1
6
2,721
0
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 6274th place
Languagesmali
LicenseMIT_X11

How to Read and Write XMP Data to Images inside .NET Apps

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1079521/How-to-Read-and-Write-XMP-Data-to-Images?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet.//Create XMP Metadata, Write It And Read From File //[C# Code Sample] // Specify the size of image by defining a Rectangle Aspose.Imaging.Rectangle rect = new Aspose.Imaging.Rectangle(0, 0, 100, 200); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRGB); tiffOptions.Photometric = TiffPhotometrics.MinIsBlack; tiffOptions.BitsPerSample = new ushort[] { 8 }; // create the brand new image just for sample purposes using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height))) { // create an instance of XMP-Header Aspose.Imaging.Xmp.XmpHeaderPi xmpHeader = new Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString()); // create an instance of Xmp-TrailerPi Aspose.Imaging.Xmp.XmpTrailerPi xmpTrailer = new Aspose.Imaging.Xmp.XmpTrailerPi(true); // create an instance of XMPmeta class to set different attributes Aspose.Imaging.Xmp.XmpMeta xmpMeta = new Aspose.Imaging.Xmp.XmpMeta(); xmpMeta.AddAttribute("Author", "Mr Smith"); xmpMeta.AddAttribute("Description", "The fake metadata value"); // create an instance of XmpPacketWrapper that contains all metadata Aspose.Imaging.Xmp.XmpPacketWrapper xmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta); // create an instacne of Photoshop package and set photoshop attributes Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage photoshopPackage = new Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage(); photoshopPackage.SetCity("London"); photoshopPackage.SetCountry("England"); photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb); photoshopPackage.SetCreatedDate(DateTime.UtcNow); // add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage); // create an instacne of DublinCore package and set dublinCore attributes Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage dublinCorePackage = new Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage(); dublinCorePackage.SetAuthor("Charles Bukowski"); dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts"); dublinCorePackage.AddValue("dc:movie", "Barfly"); // add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage); using (var ms = new MemoryStream()) { // update XMP metadata into image image.XmpData = xmpData; // Save image on the disk or in memory stream image.Save(ms); ms.Seek(0, System.IO.SeekOrigin.Begin); // Load the image from moemory stream or from disk to read/get the metadata using (var img = (TiffImage)Aspose.Imaging.Image.Load(ms)) { // getting the XMP metadata Aspose.Imaging.Xmp.XmpPacketWrapper imgXmpData = img.XmpData; foreach (Aspose.Imaging.Xmp.XmpPackage package in imgXmpData.Packages) { // use package data ... } } } } //[VB.NET Code Sample] ' Specify the size of image by defining a Rectangle Dim rect As New Aspose.Imaging.Rectangle(0, 0, 100, 200) Dim tiffOptions As New TiffOptions(TiffExpectedFormat.TiffJpegRGB) tiffOptions.Photometric = TiffPhotometrics.MinIsBlack tiffOptions.BitsPerSample = New UShort() {8} ' create the brand new image just for sample purposes Using image = New TiffImage(New TiffFrame(tiffOptions, rect.Width, rect.Height)) ' create an instance of XMP-Header Dim xmpHeader As New Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString()) ' create an instance of Xmp-TrailerPi Dim xmpTrailer As New Aspose.Imaging.Xmp.XmpTrailerPi(True) ' create an instance of XMPmeta class to set different attributes Dim xmpMeta As New Aspose.Imaging.Xmp.XmpMeta() xmpMeta.AddAttribute("Author", "Mr Smith") xmpMeta.AddAttribute("Description", "The fake metadata value") ' create an instance of XmpPacketWrapper that contains all metadata Dim xmpData As New Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta) ' create an instacne of Photoshop package and set photoshop attributes Dim photoshopPackage As New Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage() photoshopPackage.SetCity("London") photoshopPackage.SetCountry("England") photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb) photoshopPackage.SetCreatedDate(DateTime.UtcNow) ' add photoshop package into XMP metadata xmpData.AddPackage(photoshopPackage) ' create an instacne of DublinCore package and set dublinCore attributes Dim dublinCorePackage As New Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage() dublinCorePackage.SetAuthor("Charles Bukowski") dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts") dublinCorePackage.AddValue("dc:movie", "Barfly") ' add dublinCore Package into XMP metadata xmpData.AddPackage(dublinCorePackage) Using ms = New MemoryStream() ' update XMP metadata into image image.XmpData = xmpData ' Save image on the disk or in memory stream image.Save(ms) ms.Seek(0, System.IO.SeekOrigin.Begin) ' Load the image from moemory stream or from disk to read/get the metadata Using img = DirectCast(Aspose.Imaging.Image.Load(ms), TiffImage) ' getting the XMP metadata Dim imgXmpData As Aspose.Imaging.Xmp.XmpPacketWrapper = img.XmpData ' use package data ... For Each package As Aspose.Imaging.Xmp.XmpPackage In imgXmpData.Packages Next End Using End Using End Using
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus