/// <summary>Fixes the GPS Timestamp in EXIF.</summary> /// <param name="exifSchema">the EXIF schema node</param> /// <exception cref="iText.Kernel.XMP.XMPException">Thrown if the date conversion fails. /// </exception> private static void FixGPSTimeStamp(XMPNode exifSchema) { // Note: if dates are not found the convert-methods throws an exceptions, // and this methods returns. XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false); if (gpsDateTime == null) { return; } try { XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue()); if (binGpsStamp.GetYear() != 0 || binGpsStamp.GetMonth() != 0 || binGpsStamp.GetDay() != 0) { return; } XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false); otherDate = otherDate ?? XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false); XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue()); XMPCalendar cal = binGpsStamp.GetCalendar(); DateTime dt = new DateTime(binOtherDate.GetYear(), binOtherDate.GetMonth(), binOtherDate.GetDay(), cal.GetDateTime().Hour, cal.GetDateTime().Minute, cal.GetDateTime().Second, cal.GetDateTime().Millisecond); cal.SetDateTime(dt); binGpsStamp = new XMPDateTimeImpl(cal); gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGpsStamp)); } catch (XMPException) { } }
/// <summary> /// Fixes the GPS Timestamp in EXIF. </summary> /// <param name="exifSchema"> the EXIF schema node </param> /// <exception cref="XmpException"> Thrown if the date conversion fails. </exception> private static void FixGpsTimeStamp(XmpNode exifSchema) { // Note: if dates are not found the convert-methods throws an exceptions, // and this methods returns. XmpNode gpsDateTime = XmpNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false); if (gpsDateTime == null) { return; } try { XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.Value); if (binGpsStamp.Year != 0 || binGpsStamp.Month != 0 || binGpsStamp.Day != 0) { return; } XmpNode otherDate = XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false); otherDate = otherDate ?? XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false); XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.Value); XmpCalendar cal = binGpsStamp.Calendar; DateTime dt = new DateTime(binOtherDate.Year, binOtherDate.Month, binOtherDate.Day, cal.DateTime.Hour, cal.DateTime.Minute, cal.DateTime.Second, cal.DateTime.Millisecond); cal.DateTime = dt; binGpsStamp = new XmpDateTimeImpl(cal); gpsDateTime.Value = XMPUtils.ConvertFromDate(binGpsStamp); } catch (XmpException) { } }
/// <summary> /// Converts the node value to String, apply special conversions for defined /// types in XMP. /// </summary> /// <param name="value"> /// the node value to set </param> /// <returns> Returns the String representation of the node value. </returns> internal static string SerializeNodeValue(object value) { string strValue; if (value == null) { strValue = null; } else if (value is bool?) { strValue = XMPUtils.ConvertFromBoolean((bool)((bool?)value)); } else if (value is int?) { strValue = XMPUtils.ConvertFromInteger((int)((int?)value)); } else if (value is long?) { strValue = XMPUtils.ConvertFromLong((long)((long?)value)); } else if (value is double?) { strValue = XMPUtils.ConvertFromDouble((double)((double?)value)); } else if (value is XMPDateTime) { strValue = XMPUtils.ConvertFromDate((XMPDateTime)value); } else if (value is XmpCalendar) { XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((XmpCalendar)value); strValue = XMPUtils.ConvertFromDate(dt); } else if (value is byte[]) { strValue = XMPUtils.EncodeBase64((byte[])value); } else { strValue = value.ToString(); } return(strValue != null?Utils.RemoveControlChars(strValue) : null); }
/// <summary>Fixes the GPS Timestamp in EXIF.</summary> /// <param name="exifSchema">the EXIF schema node</param> /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown if the date conversion fails.</exception> private static void FixGPSTimeStamp(XMPNode exifSchema) { // Note: if dates are not found the convert-methods throws an exceptions, // and this methods returns. XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false); if (gpsDateTime == null) { return; } try { XMPDateTime binGPSStamp; XMPDateTime binOtherDate; binGPSStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue()); if (binGPSStamp.GetYear() != 0 || binGPSStamp.GetMonth() != 0 || binGPSStamp.GetDay() != 0) { return; } XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false); if (otherDate == null) { otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false); } binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue()); Sharpen.Calendar cal = binGPSStamp.GetCalendar(); cal.Set(Sharpen.CalendarEnum.Year, binOtherDate.GetYear()); cal.Set(Sharpen.CalendarEnum.Month, binOtherDate.GetMonth()); cal.Set(Sharpen.CalendarEnum.DayOfMonth, binOtherDate.GetDay()); binGPSStamp = new XMPDateTimeImpl(cal); gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGPSStamp)); } catch (XMPException) { // Don't let a missing or bad date stop other things. return; } }
/// <summary> /// Converts the node value to String, apply special conversions for defined /// types in XMP. /// </summary> /// <param name="value">the node value to set</param> /// <returns>Returns the String representation of the node value.</returns> internal static string SerializeNodeValue(object value) { string strValue; if (value == null) { strValue = null; } else { if (value is bool) { strValue = XMPUtils.ConvertFromBoolean(((bool)value)); } else { if (value is int) { strValue = XMPUtils.ConvertFromInteger(((int)value).IntValue()); } else { if (value is long) { strValue = XMPUtils.ConvertFromLong(((long)value).LongValue()); } else { if (value is double) { strValue = XMPUtils.ConvertFromDouble(((double)value).DoubleValue()); } else { if (value is XMPDateTime) { strValue = XMPUtils.ConvertFromDate((XMPDateTime)value); } else { if (value is Sharpen.GregorianCalendar) { XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((Sharpen.GregorianCalendar)value); strValue = XMPUtils.ConvertFromDate(dt); } else { if (value is sbyte[]) { strValue = XMPUtils.EncodeBase64((sbyte[])value); } else { strValue = value.ToString(); } } } } } } } } return(strValue != null?Utils.RemoveControlChars(strValue) : null); }