views:

1070

answers:

3

I want to save an image in EXIF format using System.Drawing.Image.Save or a similar method in a C# application using .NET framework v3.5. The MSDN documentation lists EXIF as an option for ImageFormat. However, it does not seem to be supported - at least not without some configuration unknown to me. When I enumerate the built-in encoders via ImageCodecInfo.GetImageEncoders() EXIF is not included. (Built in encoders on my machine (Vista Ultimate x64) are: BMP, JPEG, GIF, TIFF, and PNG.) If I save an image using the ImageFormat.Exif property, I simply get the default PNG format.

How can I save an image in EXIF format using .NET 3.5?

+1  A: 

Not an answer, just a reflection: To me, EXIF means the meta data you access via .PropertyItems on a bitmap. So, I'm used to store and retrieve EXIF data in JPG files, I've never heard of an EXIF image format...

danbystrom
"EXIF" is an acronym for EXchangeable Image file Format. More at www.exif.org
TMarshall
and there I read "EXIF stands for Exchangeable Image File Format, and is a standard for storing interchange information in image files, especially those using JPEG compression". So, that's exactly what I mean: I'm used to access EXIF info stored with JPG compressed files! :-)
danbystrom
So, maybe you want to save as Jpeg and store your EXIF data using .PropertyItems? That's the way I do it...
danbystrom
I understand the confusion. EXIF metadata can be stored in different file formats, including JFIF/JPEG. When the image data is compressed, the compression method used is JPEG and the file format is based on JFIF. Uncompressed is based on TIFF.
TMarshall
The main feature I am looking for in EXIF is the embedded JPEG compressed thumbnail. I don't care about the metadata. So maybe I should refocus on embedding a thumbnail in a standard JFIF file since it is well supported in .NET...
TMarshall
Maybe this blogpost of mine will help you: http://danbystrom.se/2009/01/05/imagegetthumbnailimage-and-beyond/ there I show how to retreive an EXIF thumbnail.
danbystrom
Very nice article! What I really need though, is to create the thumbnail in the image I am saving - not one I am opening. The image file needs to contain a thumbnail for a different application.
TMarshall
Well, you just do the complete opposite! :-) The only gotcha is how to create a PropertyItem if you don't have one to start with, since there is no public constructor for PropertyItem.
danbystrom
A: 

Have you seen this: Lossless JPEG Rewrites in C#

Igor Brejc
Thanks, that's an interesting article. It applies to JFIF files, but not EXIF. Still, it's a clever approach.
TMarshall
+4  A: 

EXIF isn't a image file format per se, but a format for meta-data found within JPEG images conforming to the DSC (Digital Still Camera) standard as specified by JEITA.

GDI+ (i.e. Microsoft .NET Framework) allows you to read/write metadata image properties via the Image.PropertyItems, however the EXIF properties exposed by GDI+ are pretty cumbersome and don't convert the values the way you would expect. A lot of work is actually needed to be able to natively read/write these values (e.g. you'd need to unpack binary fields containing specially encoded values according to the JEITA spec).

A straight-forward open-source library which implements all the standard EXIF properties can be found at http://code.google.com/p/exif-utils/ This is probably the easiest way to do this. See the simple included demo which reads in a file, prints out all the EXIF properties and then adds a property to the image.

McKAMEY