Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET C# library for lossless Exif rewriting? [closed]

Tags:

c#

.net

jpeg

exif

I have found various code and libraries for editing Exif.

But they are only lossless when the image width and height is multiple of 16.

I am looking for a library (or even a way to do it myself) to edit just the Exif portion in a JPEG file (or add Exif data if it doesn't exist yet), leaving the other data unmodified. Isn't that possible?

So far I could only locate the Exif portion (starts with 0xFFE1) but I don't understand how to read the data.

like image 520
Aximili Avatar asked Jun 24 '09 13:06

Aximili


3 Answers

You can do this without any external lib:

// Create image.
Image image1 = Image.FromFile("c:\\Photo1.jpg");

// Get a PropertyItem from image1. Because PropertyItem does not
// have public constructor, you first need to get existing PropertyItem
PropertyItem propItem = image1.GetPropertyItem(20624);

// Change the ID of the PropertyItem.
propItem.Id = 20625;

// Set the new PropertyItem for image1.
image1.SetPropertyItem(propItem);

// Save the image.
image1.Save("c:\\Photo1.jpg", ImageFormat.Jpg);

List of all possible PropertyItem ids (including exif) you can found here.

Update: Agreed, this method will re-encode image on save. But I have remembered another method, in WinXP SP2 and later there is new imaging components added - WIC, and you can use them to lossless write metadate - How-to: Re-encode a JPEG Image with Metadata.

like image 83
arbiter Avatar answered Nov 15 '22 16:11

arbiter


Here are the specifications for the Exif interchange format, if you plan to code your own library for editing tags.

http://www.exif.org/specifications.html

Here's a library written in Perl that meets your needs that you may be able to learn from:

http://www.sno.phy.queensu.ca/~phil/exiftool/

Here's a decent .NET library for Exif evaluation from The Code Project:

http://www.codeproject.com/KB/graphics/exiftagcol.aspx

like image 27
LBushkin Avatar answered Nov 15 '22 17:11

LBushkin


exiv2net library (a .NET wrapper on top of exiv2) may be what you're looking for.

like image 29
Pawel Marciniak Avatar answered Nov 15 '22 17:11

Pawel Marciniak