public static object GetValueObject(PropertyItem property) { if (property == null) return null; switch ((PropertyTagType)property.Type) { //ASCII case PropertyTagType.ASCII: ASCIIEncoding encoding = new ASCIIEncoding(); return encoding.GetString(property.Value, 0, property.Len - 1); //BYTE case PropertyTagType.Byte: if (property.Len == 1) return property.Value[0]; else return property.Value; //LONG case PropertyTagType.Long: uint[] resultLong = new uint[property.Len / 4]; for (int i = 0; i < resultLong.Length; i++) resultLong[i] = BitConverter.ToUInt32(property.Value, i * 4); if (resultLong.Length == 1) return resultLong[0]; else return resultLong; //SHORT case PropertyTagType.Short: ushort[] resultShort = new ushort[property.Len / 2]; for (int i = 0; i < resultShort.Length; i++) resultShort[i] = BitConverter.ToUInt16(property.Value, i * 2); if (resultShort.Length == 1) return resultShort[0]; else return resultShort; //SLONG case PropertyTagType.SLONG: int[] resultSLong = new int[property.Len / 4]; for (int i = 0; i < resultSLong.Length; i++) resultSLong[i] = BitConverter.ToInt32(property.Value, i * 4); if (resultSLong.Length == 1) return resultSLong[0]; else return resultSLong; //RATIONAL case PropertyTagType.Rational: Fraction[] resultRational = new Fraction[property.Len / 8]; uint uNumerator; uint uDenumerator; for (int i = 0; i < resultRational.Length; i++) { uNumerator = BitConverter.ToUInt32(property.Value, i * 8); uDenumerator = BitConverter.ToUInt32(property.Value, i * 8 + 4); resultRational[i] = new Fraction(uNumerator, uDenumerator); } if (resultRational.Length == 1) return resultRational[0]; else return resultRational; //SRATIONAL case PropertyTagType.SRational: Fraction[] resultSRational = new Fraction[property.Len / 8]; int sNumerator; int sDenumerator; for (int i = 0; i < resultSRational.Length; i++) { sNumerator = BitConverter.ToInt32(property.Value, i * 8); sDenumerator = BitConverter.ToInt32(property.Value, i * 8 + 4); resultSRational[i] = new Fraction(sNumerator, sDenumerator); } if (resultSRational.Length == 1) return resultSRational[0]; else return resultSRational; //UNDEFINE default: if (property.Len == 1) return property.Value[0]; else return property.Value; } }
public static object GetValueObject(PropertyItem property) { if (property == null) { return(null); } switch ((PropertyTagType)property.Type) { //ASCII case PropertyTagType.ASCII: ASCIIEncoding encoding = new ASCIIEncoding(); return(encoding.GetString(property.Value, 0, property.Len - 1)); //BYTE case PropertyTagType.Byte: if (property.Len == 1) { return(property.Value[0]); } else { return(property.Value); } //LONG case PropertyTagType.Long: uint[] resultLong = new uint[property.Len / 4]; for (int i = 0; i < resultLong.Length; i++) { resultLong[i] = BitConverter.ToUInt32(property.Value, i * 4); } if (resultLong.Length == 1) { return(resultLong[0]); } else { return(resultLong); } //SHORT case PropertyTagType.Short: ushort[] resultShort = new ushort[property.Len / 2]; for (int i = 0; i < resultShort.Length; i++) { resultShort[i] = BitConverter.ToUInt16(property.Value, i * 2); } if (resultShort.Length == 1) { return(resultShort[0]); } else { return(resultShort); } //SLONG case PropertyTagType.SLONG: int[] resultSLong = new int[property.Len / 4]; for (int i = 0; i < resultSLong.Length; i++) { resultSLong[i] = BitConverter.ToInt32(property.Value, i * 4); } if (resultSLong.Length == 1) { return(resultSLong[0]); } else { return(resultSLong); } //RATIONAL case PropertyTagType.Rational: Fraction[] resultRational = new Fraction[property.Len / 8]; uint uNumerator; uint uDenumerator; for (int i = 0; i < resultRational.Length; i++) { uNumerator = BitConverter.ToUInt32(property.Value, i * 8); uDenumerator = BitConverter.ToUInt32(property.Value, i * 8 + 4); resultRational[i] = new Fraction(uNumerator, uDenumerator); } if (resultRational.Length == 1) { return(resultRational[0]); } else { return(resultRational); } //SRATIONAL case PropertyTagType.SRational: Fraction[] resultSRational = new Fraction[property.Len / 8]; int sNumerator; int sDenumerator; for (int i = 0; i < resultSRational.Length; i++) { sNumerator = BitConverter.ToInt32(property.Value, i * 8); sDenumerator = BitConverter.ToInt32(property.Value, i * 8 + 4); resultSRational[i] = new Fraction(sNumerator, sDenumerator); } if (resultSRational.Length == 1) { return(resultSRational[0]); } else { return(resultSRational); } //UNDEFINE default: if (property.Len == 1) { return(property.Value[0]); } else { return(property.Value); } } }