1
// ==========================================================
2
// FreeImage 3 .NET wrapper
3
// Original FreeImage 3 functions and .NET compatible derived functions
5
// Design and implementation by
6
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
7
// - Carsten Klein (cklein05@users.sourceforge.net)
10
// - David Boland (davidboland@vodafone.ie)
12
// Main reference : MSDN Knowlede Base
14
// This file is part of FreeImage 3
16
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
17
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
18
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
19
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
20
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
21
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
22
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
23
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
26
// Use at your own risk!
27
// ==========================================================
29
// ==========================================================
32
// $Date: 2009/02/27 16:34:59 $
33
// $Id: ImageMetadata.cs,v 1.7 2009/02/27 16:34:59 cklein05 Exp $
34
// ==========================================================
37
using System.Collections;
38
using System.Collections.Generic;
39
using System.Reflection;
40
using System.Diagnostics;
42
namespace FreeImageAPI.Metadata
45
/// Class handling metadata of a FreeImage bitmap.
47
public class ImageMetadata : IEnumerable, IComparable, IComparable<ImageMetadata>
49
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
50
private readonly List<MetadataModel> data;
51
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
52
private readonly FIBITMAP dib;
53
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
54
private bool hideEmptyModels;
57
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
58
/// showing all known models.
60
/// <param name="dib">Handle to a FreeImage bitmap.</param>
61
public ImageMetadata(FIBITMAP dib) : this(dib, false) { }
64
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
65
/// showing or hiding empry models.
67
/// <param name="dib">Handle to a FreeImage bitmap.</param>
68
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
69
/// will be hidden until a tag to this model is added.</param>
70
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
72
if (dib.IsNull) throw new ArgumentNullException("dib");
73
data = new List<MetadataModel>(FreeImage.FREE_IMAGE_MDMODELS.Length);
75
this.hideEmptyModels = hideEmptyModels;
77
data.Add(new MDM_ANIMATION(dib));
78
data.Add(new MDM_COMMENTS(dib));
79
data.Add(new MDM_CUSTOM(dib));
80
data.Add(new MDM_EXIF_EXIF(dib));
81
data.Add(new MDM_EXIF_GPS(dib));
82
data.Add(new MDM_INTEROP(dib));
83
data.Add(new MDM_EXIF_MAIN(dib));
84
data.Add(new MDM_MAKERNOTE(dib));
85
data.Add(new MDM_GEOTIFF(dib));
86
data.Add(new MDM_IPTC(dib));
87
data.Add(new MDM_NODATA(dib));
88
data.Add(new MDM_XMP(dib));
92
/// Gets or sets the <see cref="MetadataModel"/> of the specified type.
93
/// <para>In case the getter returns <c>null</c> the model is not contained
94
/// by the list.</para>
95
/// <para><c>null</c> can be used calling the setter to destroy the model.</para>
97
/// <param name="model">Type of the model.</param>
98
/// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/> object of the specified type.</returns>
99
public MetadataModel this[FREE_IMAGE_MDMODEL model]
103
for (int i = 0; i < data.Count; i++)
105
if (data[i].Model == model)
107
if (!data[i].Exists && hideEmptyModels)
119
/// Gets or sets the <see cref="FreeImageAPI.Metadata.MetadataModel"/> at the specified index.
120
/// <para>In case the getter returns <c>null</c> the model is not contained
121
/// by the list.</para>
122
/// <para><c>null</c> can be used calling the setter to destroy the model.</para>
124
/// <param name="index">Index of the <see cref="FreeImageAPI.Metadata.MetadataModel"/> within
125
/// this instance.</param>
126
/// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/>
127
/// object at the specified index.</returns>
128
public MetadataModel this[int index]
132
if (index < 0 || index >= data.Count)
134
throw new ArgumentOutOfRangeException("index");
136
return (hideEmptyModels && !data[index].Exists) ? null : data[index];
141
/// Returns a list of all visible
142
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
144
public List<MetadataModel> List
150
List<MetadataModel> result = new List<MetadataModel>();
151
for (int i = 0; i < data.Count; i++)
168
/// Adds new tag to the bitmap or updates its value in case it already exists.
169
/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
171
/// <param name="tag">The tag to add or update.</param>
172
/// <returns>Returns true on success, false on failure.</returns>
173
/// <exception cref="ArgumentNullException">
174
/// <paramref name="tag"/> is null.</exception>
175
public bool AddTag(MetadataTag tag)
177
for (int i = 0; i < data.Count; i++)
179
if (tag.Model == data[i].Model)
181
return data[i].AddTag(tag);
188
/// Returns the number of visible
189
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
198
for (int i = 0; i < data.Count; i++)
215
/// Gets or sets whether empty
216
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see> are hidden.
218
public bool HideEmptyModels
222
return hideEmptyModels;
226
hideEmptyModels = value;
231
/// Retrieves an object that can iterate through the individual
232
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>
233
/// in this <see cref="ImageMetadata"/>.
235
/// <returns>An <see cref="IEnumerator"/> for this <see cref="ImageMetadata"/>.</returns>
236
public IEnumerator GetEnumerator()
240
List<MetadataModel> tempList = new List<MetadataModel>(data.Count);
241
for (int i = 0; i < data.Count; i++)
245
tempList.Add(data[i]);
248
return tempList.GetEnumerator();
252
return data.GetEnumerator();
257
/// Compares this instance with a specified <see cref="Object"/>.
259
/// <param name="obj">An object to compare with this instance.</param>
260
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
261
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="ImageMetadata"/>.</exception>
262
public int CompareTo(object obj)
268
if (!(obj is ImageMetadata))
270
throw new ArgumentException("obj");
272
return CompareTo((ImageMetadata)obj);
276
/// Compares this instance with a specified <see cref="ImageMetadata"/> object.
278
/// <param name="other">A <see cref="ImageMetadata"/> to compare.</param>
279
/// <returns>A signed number indicating the relative values of this instance
280
/// and <paramref name="other"/>.</returns>
281
public int CompareTo(ImageMetadata other)
283
return this.dib.CompareTo(other.dib);
b'\\ No newline at end of file'