static void PrintFileProperties(string fileName) { Console.WriteLine(Path.GetFileName(fileName)); using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(fileName)) { PropertyItem[] properties = bitmap.PropertyItems; foreach (PropertyItem prop in properties) { PropertyTagType type = (PropertyTagType)prop.Type; Console.WriteLine(" {0} - 0x{1:X4} - {2}", type, prop.Id, prop.Len); if (prop.Id == Program.PropertyTagGpsLatitude) { Console.Write(" Lat: "); PrintLatLong(prop.Value); } else if (prop.Id == Program.PropertyTagGpsLongitude) { Console.Write(" Lng: "); PrintLatLong(prop.Value); } else if (prop.Id == Program.PropertyTagGpsLongitudeRef) { Console.WriteLine(" LngRef: {0}", (char)prop.Value[0]); } else if (prop.Id == Program.PropertyTagGpsLatitudeRef) { Console.WriteLine(" LatRef: {0}", (char)prop.Value[0]); } } } }
static public PropertyItem CreateInstance(int PropertyTagId, PropertyTagType propertyTagType, byte[] PropertyValue) { PropertyItem retVal = CreateInstance(); retVal.Id = PropertyTagId; retVal.Len = PropertyValue.Length; retVal.Type = (short)propertyTagType; retVal.Value = PropertyValue; return(retVal); }
/// <summary> /// プロパティを設定する。 /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <param name="len"></param> /// <param name="value"></param> /// <returns></returns> private ImagePropertyItemWriter SetPropertyItem( PropertyTags id, PropertyTagType type, int len, byte[] value) { propSeed.Id = (int)id; propSeed.Type = (short)type; propSeed.Len = len; propSeed.Value = value; LogPropertyItem("[PropertyItemAdder.SetPropertyItem] ", propSeed); image.SetPropertyItem(propSeed); return(this); }
private static bool ReadProperty <T>(Image img, PropertyTag tag, PropertyTagType type, int?length, out T value) { if (Array.IndexOf(img.PropertyIdList, (int)tag) != -1) { var property = img.GetPropertyItem((int)tag); if (property.Type == (short)type && ParseValue(type, length, property.Value, out var obj) && obj is T asT) { value = asT; return(true); } } value = default; return(false); }
public PropertyItem CreateNewPropertyItem(int id, PropertyTagType tagType, byte[] value) { Bitmap oBitmap = Base64_To_Bitmap(Icon_Base_8_8); PropertyItem[] propItems = oBitmap.PropertyItems; if (propItems.Length != 0) { propItems[0].Id = id; // 0x010E = PropertyTagImageDescription. propItems[0].Type = (short)tagType; // Null-terminated ASCII string. propItems[0].Value = value; propItems[0].Len = value.Length; // Length (+1 ?). return(propItems[0]); } else { return(null); } }
/// <summary> /// - PropertyItem nema verejny konstruktor, proto se musi ziskat kopii z j*z nejakeho existujiciho. Zatim /// predpoklada, ze tu j*z vzdy bude nejaky PropertyItem a ten zkopiruju ... pokud bych chtel pridavat /// do obrazku kde neni jeste zadny, musim si ho vytvorit z jineho obrazku (ten bu mohl byt napr v resourcich) /// </summary> /// <param name="Type"></param> /// <param name="TagId"></param> /// <param name="Len"></param> /// <param name="Value"></param> /// <returns></returns> private PropertyItem CreatePropertyItem(PropertyTagType Type, PropertyTagId TagId, int Len, byte[] Value) { CheckSrcBitmap(); PropertyItem PItem = null; // zjistit prvni item - z neho si zkopiruju instanci PropertyItemu ! int[] IdList = SourceBitmap.PropertyIdList; if (IdList.Length > 0) { PItem = SrcBitmap.GetPropertyItem(IdList[0]); // zkopirovani mych aktualnich dat PItem.Type = (short)Type; PItem.Id = (int)TagId; PItem.Len = Len; PItem.Value = new byte[Value.Length]; Value.CopyTo(PItem.Value, 0); } return(PItem); }
static string PropertyToString(PropertyTagType type, byte[] bytes) { switch(type) { case PropertyTagType.Byte: { return bytes[0].ToString(); } case PropertyTagType.ASCII: { StringBuilder sb; sb = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { if (!Char.IsControl((char)bytes[i])) { sb.Append((char)bytes[i]); } else { sb.Append("\\" + bytes[i].ToString()); } } return sb.ToString(); } case PropertyTagType.Short: { ushort s; s = (ushort)(bytes[1] * 256 + bytes[0]); return s.ToString(); } case PropertyTagType.Long: { uint l; l = (uint)(bytes[3] * 16777216 + bytes[2] * 65536 + bytes[1] * 256 + bytes[0]); return l.ToString(); } case PropertyTagType.SRational: { ushort numerator; ushort denominator; numerator = (ushort)(bytes[1] * 256 + bytes[0]); denominator = (ushort)(bytes[3] * 256 + bytes[2]); return String.Format("{0} / {1})", numerator, denominator); } case PropertyTagType.Rational: { uint numerator; uint denominator; numerator = (uint)(bytes[3] * 16777216 + bytes[2] * 65536 + bytes[1] * 256 + bytes[0]); denominator = (uint)(bytes[7] * 16777216 + bytes[6] * 65536 + bytes[5] * 256 + bytes[4]); return String.Format("{0} / {1}", numerator, denominator); } default: { return "<"+type.ToString()+">"; } } }
/// <summary> /// /// </summary> /// <param name="hex"></param> /// <param name="type"></param> /// <param name="value"></param> public ExifProperty(int hex, PropertyTagType type, byte[] value) { this.Hex = hex; this.Type = type; this.Value = value; }
private static bool ParseValue(PropertyTagType type, int?length, byte[] value, out object result) { if (length != null && length.Value != value.Length) { result = null; return(false); } var len = length ?? value.Length; switch (type) { case PropertyTagType.ByteArray: case PropertyTagType.ASCII: result = value; return(true); case PropertyTagType.UInt16: if (len % sizeof(ushort) != 0) { result = null; return(false); } else { var array = new ushort[len / sizeof(ushort)]; result = array; for (var i = 0; i < len; i += sizeof(ushort)) { array[i / sizeof(ushort)] = BitConverter.ToUInt16(value, i); // TODO: Consider endianness. } return(true); } case PropertyTagType.UInt32: if (len % sizeof(uint) != 0) { result = null; return(false); } else { var array = new uint[len / sizeof(uint)]; result = array; for (var i = 0; i < len; i += sizeof(uint)) { array[i / sizeof(uint)] = BitConverter.ToUInt32(value, i); // TODO: Consider endianness. } return(true); } case PropertyTagType.URational: if (len % (sizeof(uint) * 2) != 0) { result = null; return(false); } else { var array = new FractionUInt32[len / (sizeof(uint) * 2)]; result = array; for (var i = 0; i < len / (sizeof(uint) * 2); i += 1) { // TODO: Consider endianness. array[i] = new FractionUInt32( BitConverter.ToUInt32(value, sizeof(uint) * (i * 2)), BitConverter.ToUInt32(value, sizeof(uint) * (i * 2 + 1))); } return(true); } case PropertyTagType.Int32: if (len % sizeof(int) != 0) { result = null; return(false); } else { var array = new int[len / sizeof(int)]; result = array; for (var i = 0; i < len; i += sizeof(int)) { array[i / sizeof(int)] = BitConverter.ToInt32(value, i); // TODO: Consider endianness. } return(true); } case PropertyTagType.SRational: if (len % (sizeof(int) * 2) != 0) { result = null; return(false); } else { var array = new FractionInt32[len / (sizeof(int) * 2)]; result = array; for (var i = 0; i < len / (sizeof(int) * 2); i += sizeof(int)) { // TODO: Consider endianness. array[i] = new FractionInt32( BitConverter.ToInt32(value, sizeof(uint) * (i * 2)), BitConverter.ToInt32(value, sizeof(uint) * (i * 2 + 1))); } return(true); } case PropertyTagType.Any: default: result = null; return(false); } }
static string PropertyToString(PropertyTagType type, byte[] bytes) { switch (type) { case PropertyTagType.Byte: { return(bytes[0].ToString()); } case PropertyTagType.ASCII: { StringBuilder sb; sb = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { if (!Char.IsControl((char)bytes[i])) { sb.Append((char)bytes[i]); } else { sb.Append("\\" + bytes[i].ToString()); } } return(sb.ToString()); } case PropertyTagType.Short: { ushort s; s = (ushort)(bytes[1] * 256 + bytes[0]); return(s.ToString()); } case PropertyTagType.Long: { uint l; l = (uint)(bytes[3] * 16777216 + bytes[2] * 65536 + bytes[1] * 256 + bytes[0]); return(l.ToString()); } case PropertyTagType.SRational: { ushort numerator; ushort denominator; numerator = (ushort)(bytes[1] * 256 + bytes[0]); denominator = (ushort)(bytes[3] * 256 + bytes[2]); return(String.Format("{0} / {1})", numerator, denominator)); } case PropertyTagType.Rational: { uint numerator; uint denominator; numerator = (uint)(bytes[3] * 16777216 + bytes[2] * 65536 + bytes[1] * 256 + bytes[0]); denominator = (uint)(bytes[7] * 16777216 + bytes[6] * 65536 + bytes[5] * 256 + bytes[4]); return(String.Format("{0} / {1}", numerator, denominator)); } default: { return("<" + type.ToString() + ">"); } } }
private string Write7_PropertyTagType(PropertyTagType v) { switch (v) { case PropertyTagType.PixelFormat4bppIndexed: return "PixelFormat4bppIndexed"; case PropertyTagType.Byte: return "Byte"; case PropertyTagType.ASCII: return "ASCII"; case PropertyTagType.Short: return "Short"; case PropertyTagType.Long: return "Long"; case PropertyTagType.Rational: return "Rational"; case PropertyTagType.Undefined: return "Undefined"; case PropertyTagType.SLONG: return "SLONG"; case PropertyTagType.SRational: return "SRational"; } long num = (long) v; throw base.CreateInvalidEnumValueException(num.ToString(CultureInfo.InvariantCulture), "Nomad.Commons.PropertyTagType"); }