/// <summary> /// Gets a .NET PropertyItem for this metadata tag. /// </summary> /// <returns>The .NET PropertyItem.</returns> public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem() { System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem(); item.Id = ID; item.Len = (int)Length; item.Type = (short)Type; FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len); return(item); }
/// <summary> /// Sets the value of this tag to the value of <paramref name="value"/> /// using the given type. /// </summary> /// <param name="value">New value of the tag.</param> /// <param name="type">Data-type of the tag.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <paramref name="value"/> is a null reference. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="type"/> is FIDT_ASCII and /// <paramref name="value"/> is not String. /// <paramref name="type"/> is not FIDT_ASCII and /// <paramref name="value"/> is not Array.</exception> /// <exception cref="NotSupportedException"> /// <paramref name="type"/> is FIDT_NOTYPE.</exception> private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) { if (value == null) { throw new ArgumentNullException("value"); } byte[] data = null; if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) { string tempValue = value as string; if (tempValue == null) { throw new ArgumentException("value"); } Type = type; Length = Count = (uint)tempValue.Length; data = new byte[Length]; for (int i = 0; i < tempValue.Length; i++) { data[i] = (byte)tempValue[i]; } } else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) { throw new NotSupportedException("type is not supported."); } else { Array array = value as Array; if (array == null) { throw new ArgumentException("value"); } if (array.Length != 0) { if (!CheckType(array.GetValue(0).GetType(), type)) { throw new ArgumentException("The type of value is incorrect."); } } Type = type; Count = (uint)array.Length; Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); data = new byte[Length]; FreeImage.CopyMemory(data, array, Length); } return(FreeImage.SetTagValue(tag, data)); }
/// <summary> /// Sets the value of this tag to the value of <paramref name="value"/> /// using the given type. /// </summary> /// <param name="value">New value of the tag.</param> /// <param name="type">Data-type of the tag.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// <paramref name="value"/> is a null reference. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="type"/> is FIDT_ASCII and /// <paramref name="value"/> is not String. /// <paramref name="type"/> is not FIDT_ASCII and /// <paramref name="value"/> is not Array.</exception> /// <exception cref="NotSupportedException"> /// <paramref name="type"/> is FIDT_NOTYPE.</exception> private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type) { if (value == null) { throw new ArgumentNullException("value"); } byte[] data = null; if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII) { string tempValue = value as string; if (tempValue == null) { throw new ArgumentException("value"); } Type = type; Count = (uint)(tempValue.Length + 1); Length = (uint)((tempValue.Length * sizeof(byte)) + 1); data = new byte[Length + 1]; for (int i = 0; i < tempValue.Length; i++) { data[i] = (byte)tempValue[i]; } data[data.Length - 1] = 0; } else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE) { throw new NotSupportedException(); } else { Array array = value as Array; if (array == null) { throw new ArgumentException("value"); } Type = type; Count = (uint)array.Length; Length = (uint)(array.Length * Marshal.SizeOf(idList[type])); data = new byte[Length]; GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned); void * src = (void *)Marshal.UnsafeAddrOfPinnedArrayElement(array, 0); fixed(byte *dst = data) { FreeImage.CopyMemory(dst, src, Length); } handle.Free(); } return(FreeImage.SetTagValue(tag, data)); }