public static byte[] ConvertData(Type dataType, ExifType targetType, object value) { switch (targetType) { case ExifType.Ascii: { return(Encoding.ASCII.GetBytes(Convert.ToString(value) + '\0')); } case ExifType.Byte: case ExifType.Raw: { if (dataType == typeof(UnicodeEncoding)) { return(Encoding.Unicode.GetBytes(Convert.ToString(value) + '\0')); } return(ExifEncoder.WriteBytes(value)); } case ExifType.Int32: { return(ExifEncoder.WriteInt32(value)); } case ExifType.Rational: { return(ExifEncoder.WriteRational(value)); } case ExifType.UInt16: { return(ExifEncoder.WriteUInt16(value)); } case ExifType.UInt32: { return(ExifEncoder.WriteUInt32(value)); } case ExifType.URational: { return(ExifEncoder.WriteURational(value)); } default: { throw new NotImplementedException(String.Format("Encoding for EXIF type \"{0}\" has not yet been implemented.", targetType)); } } }
public static object ConvertTo(this byte[] bytes, ExifType type, int len) { switch (type) { case ExifType.Byte: return(bytes); case ExifType.String: return(Encoding.ASCII.GetString(bytes)); case ExifType.UInt16: return(BitConverter.ToUInt16(bytes.Safe(2), 0)); case ExifType.UInt32: return(BitConverter.ToUInt32(bytes.Safe(4), 0)); case ExifType.URational: if (len > 8) { return(URationalArray(bytes, len)); } else { return(URationalFromBytes(bytes, 0)); } case ExifType.Object: return(bytes); case ExifType.Int32: return(BitConverter.ToInt32(bytes.Safe(4), 0)); case ExifType.Long: return(BitConverter.ToInt64(bytes.Safe(8), 0)); case ExifType.Rational: if (len > 8) { return(RationalArray(bytes, len)); } else { return(RationalFromBytes(bytes, 0)); } default: return(bytes); } }
public static object ConvertTo(this byte[] bytes, ExifType type, int len) { switch (type) { case ExifType.Byte: return(bytes); case ExifType.String: return(Encoding.ASCII.GetString(bytes)); case ExifType.UInt16: return(BitConverter.ToUInt16(bytes.Safe(2), 0)); case ExifType.UInt32: return(BitConverter.ToUInt32(bytes.Safe(4), 0)); case ExifType.URational: return(new URational { Denominator = BitConverter.ToUInt32(bytes, 4), Numerator = BitConverter.ToUInt32(bytes, 0) }); case ExifType.Object: return(bytes); case ExifType.Int32: return(BitConverter.ToInt32(bytes.Safe(4), 0)); case ExifType.Long: return(BitConverter.ToInt64(bytes.Safe(8), 0)); case ExifType.Rational: return(new Rational { Denominator = BitConverter.ToInt32(bytes, 0), Numerator = BitConverter.ToInt32(bytes, 4) }); default: return(bytes); } }
/// <summary> /// Ctor /// </summary> /// <param name="property"></param> public ExifProperty(PropertyItem property) { this.id = property.Id; this.type = (ExifType)property.Type; this.value = ExifDecoder.FromPropertyItem(property); }
/// <summary> /// Converts a property item to an object or array of objects. /// </summary> /// <param name="propertyItem">the property item to convert</param> /// <returns>the property value</returns> public static object FromPropertyItem(PropertyItem propertyItem) { if (propertyItem == null) { return(null); } object data = null; ExifTag tag = ExifTag.Unknown; Type dataType = null; if (Enum.IsDefined(typeof(ExifTag), propertyItem.Id)) { tag = (ExifTag)propertyItem.Id; dataType = ExifDataTypeAttribute.GetDataType(tag); } ExifType type = (ExifType)propertyItem.Type; switch (type) { case ExifType.Ascii: { // The value represents an array of chars terminated with null ('\0') char data = Encoding.ASCII.GetString(propertyItem.Value).TrimEnd('\0'); break; } case ExifType.Byte: { switch (tag) { case ExifTag.MSTitle: case ExifTag.MSSubject: case ExifTag.MSAuthor: case ExifTag.MSKeywords: case ExifTag.MSComments: { // The value represents an array of unicode bytes terminated with null ('\0') char data = Encoding.Unicode.GetString(propertyItem.Value).TrimEnd('\0'); break; } default: { // The value represents an array of bytes data = propertyItem.Value; break; } } break; } case ExifType.Raw: { // The value represents an array of bytes data = propertyItem.Value; break; } case ExifType.UInt16: { // The value represents an array of unsigned 16-bit integers. int count = propertyItem.Len / UInt16Size; ushort[] result = new ushort[count]; for (int i = 0; i < count; i++) { result[i] = ReadUInt16(propertyItem.Value, i * UInt16Size); } data = result; break; } case ExifType.Int32: { // The value represents an array of signed 32-bit integers. int count = propertyItem.Len / Int32Size; int[] result = new int[count]; for (int i = 0; i < count; i++) { result[i] = ReadInt32(propertyItem.Value, i * Int32Size); } data = result; break; } case ExifType.UInt32: { // The value represents an array of unsigned 32-bit integers. int count = propertyItem.Len / UInt32Size; uint[] result = new uint[count]; for (int i = 0; i < count; i++) { result[i] = ReadUInt32(propertyItem.Value, i * UInt32Size); } data = result; break; } case ExifType.Rational: { // The value represents an array of signed rational numbers // Numerator is an Int32 value, denominator a UInt32 value. int count = propertyItem.Len / RationalSize; Rational <int>[] result = new Rational <int> [count]; for (int i = 0; i < count; i++) { result[i] = new Rational <int>( ReadInt32(propertyItem.Value, i * RationalSize), ReadInt32(propertyItem.Value, i * RationalSize + Int32Size)); } data = result; break; } case ExifType.URational: { // The value represents an array of signed rational numbers // Numerator and denominator are UInt32 values. int count = propertyItem.Len / URationalSize; Rational <uint>[] result = new Rational <uint> [count]; for (int i = 0; i < count; i++) { result[i] = new Rational <uint>( ReadUInt32(propertyItem.Value, i * URationalSize), ReadUInt32(propertyItem.Value, i * URationalSize + UInt32Size)); } data = result; break; } default: { data = propertyItem.Value; break; } } return(ExifDecoder.ConvertData(dataType, data)); }
/// <summary> /// Ctor /// </summary> /// <param name="ns">fully qualified XMP namespace URI</param> public ExifPropertyAttribute(ExifType valueType, XmpQuantity quantity) { this.ValueType = valueType; this.Quantity = quantity; }
/// <summary> /// Ctor /// </summary> /// <param name="ns">fully qualified XMP namespace URI</param> public ExifPropertyAttribute(ExifType valueType) { this.ValueType = valueType; }
/// <summary> /// Ctor /// </summary> /// <param name="type"></param> /// <param name="exifType"></param> public ExifDataTypeAttribute(Type type, ExifType exifType) { this.dataType = type; this.exifType = exifType; }
/// <summary> /// Ctor /// </summary> /// <param name="exifType"></param> public ExifDataTypeAttribute(ExifType exifType) { this.exifType = exifType; }
public bool SetParameter(int id, byte[] data, ExifType type, bool rewrite = true) { throw new NotImplementedException(); }