Skip to content

Commit 91ef4e6

Browse files
committed
feat(exif): Enable EXIF Writing using FIMD_EXIF_RAW
FreeImage keeps two separate copies of Exif Metadata in memory: - One is used/found in MDM_EXIF_MAIN and its extensions(e.g. MDM_EXIF_GPS). - Another one is used when files are actually written that support the EXIF Format. - In some cases you want to access, the raw data. - A good example of this is when using MetadataModel.DestroyModel to wipe EXIF data on an image that you wanted persisted if that file is exported again from FreeImage. - DestoryModel was also corrected to DestroyModel, this will result in a breaking change version but that's worth it! With this you can use the following to clear and persist that "clearing" of the exif data on a FreeImage image: ```cs ImageMetadata imageMetadata = new ImageMetadata(dib, true, true); var model = imageMetadata[FREE_IMAGE_MDMODEL.FIMD_EXIF_RAW]; model.DestroyModel(); ``` When you then write that subsequent image to a file, the file will not contain any EXIF data! This is based on: - https://sourceforge.net/p/freeimage/discussion/36111/thread/2d087f91/ where i discovered FIMD_EXIF_RAW - https://sourceforge.net/p/freeimage/discussion/36111/thread/8233f5bc/ where I learnt how you might use it. As this change doesn't touch the native library, you won't need to compile that again. This is a purely .NET change. -
1 parent 51eaeb3 commit 91ef4e6

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ public class ImageMetadata : IEnumerable, IComparable, IComparable<ImageMetadata
6060
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6161
public ImageMetadata(FIBITMAP dib) : this(dib, false) { }
6262

63-
/// <summary>
64-
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
65-
/// showing or hiding empry models.
66-
/// </summary>
67-
/// <param name="dib">Handle to a FreeImage bitmap.</param>
68-
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
63+
/// <summary>
64+
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
65+
/// showing or hiding empry models.
66+
/// </summary>
67+
/// <param name="dib">Handle to a FreeImage bitmap.</param>
68+
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
6969
/// will be hidden until a tag to this model is added.</param>
70-
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
70+
/// <param name="includeRaw">When <b>true</b>, include raw byte access to EXIF, <see cref="MDM_EXIF_RAW"/>.
71+
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels, bool includeRaw = false)
7172
{
7273
if (dib.IsNull) throw new ArgumentNullException("dib");
7374
data = new List<MetadataModel>(FreeImage.FREE_IMAGE_MDMODELS.Length);
@@ -86,6 +87,10 @@ public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
8687
data.Add(new MDM_IPTC(dib));
8788
data.Add(new MDM_NODATA(dib));
8889
data.Add(new MDM_XMP(dib));
90+
91+
// This is based on: https://sourceforge.net/p/freeimage/discussion/36111/thread/2d087f91/
92+
if (includeRaw)
93+
data.Add(new MDM_EXIF_RAW(dib));
8994
}
9095

9196
/// <summary>

Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public bool RemoveTag(string key)
148148
/// which will remove all tags of this model from the bitmap.
149149
/// </summary>
150150
/// <returns>Returns true on success, false on failure.</returns>
151-
public bool DestoryModel()
151+
public bool DestroyModel()
152152
{
153153
return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero);
154154
}

Wrapper/FreeImage.NET/cs/Library/Classes/MetadataModels.cs

+28
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,34 @@ public override FREE_IMAGE_MDMODEL Model
384384
}
385385
}
386386

387+
/// <summary>
388+
/// Represents a collection of all tags contained in the metadata model
389+
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_RAW"/>.
390+
/// </summary>
391+
/// <remarks>
392+
/// FreeImage keeps two separate copies of Exif Metadata in memory.
393+
/// One is used/found in <see cref="MDM_EXIF_MAIN"/> and its extensions(e.g. <see cref="MDM_EXIF_GPS"/>).
394+
/// Another one is used when files are actually written that support the EXIF Format. In some cases you want to access, the raw data.
395+
/// A good example of this is when using <see cref="MetadataModel.DestroyModel"/> to wipe EXIF data on an image,
396+
/// that you want persisted if that file is exported again from FreeImage.
397+
/// </remarks>
398+
public class MDM_EXIF_RAW : MetadataModel
399+
{
400+
/// <summary>
401+
/// Initializes a new instance of this class.
402+
/// </summary>
403+
/// <param name="dib">Handle to a FreeImage bitmap.</param>
404+
public MDM_EXIF_RAW(FIBITMAP dib) : base(dib) { }
405+
406+
/// <summary>
407+
/// Retrieves the datamodel that this instance represents.
408+
/// </summary>
409+
public override FREE_IMAGE_MDMODEL Model
410+
{
411+
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_RAW; }
412+
}
413+
}
414+
387415
/// <summary>
388416
/// Represents a collection of all tags contained in the metadata model
389417
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF"/>.

Wrapper/FreeImage.NET/cs/Library/Enumerations/FREE_IMAGE_MDMODEL.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public enum FREE_IMAGE_MDMODEL
8787
/// <summary>
8888
/// Used to attach other metadata types to a dib
8989
/// </summary>
90-
FIMD_CUSTOM = 10
90+
FIMD_CUSTOM = 10,
91+
92+
/// <summary>
93+
/// Raw access to EXIF.
94+
/// </summary>
95+
/// <remarks>This is based on: https://sourceforge.net/p/freeimage/discussion/36111/thread/2d087f91/</remarks>
96+
FIMD_EXIF_RAW = 11
9197
}
9298
}

0 commit comments

Comments
 (0)