Пример #1
0
        private void SetPropertyItemString(System.Drawing.Image image, PropertyTagId id, String value)
        {
            byte[]       buffer   = Encoding.Unicode.GetBytes(value);
            PropertyItem propItem = image.GetPropertyItem((int)id);

            propItem.Len   = buffer.Length;
            propItem.Value = buffer;
            image.SetPropertyItem(propItem);
        }
        /// <summary>
        /// Gets an IExifValueUndefinedExtractor for the specific tagId
        /// </summary>
        /// <param name="tagId">The Exif Tag Id</param>
        /// <returns>An IExifValueUndefinedExtractor</returns>
        internal static IExifValueUndefinedExtractor GetExifValueUndefinedExtractor(PropertyTagId tagId)
        {
            ExifValueUndefinedExtractorAttribute attribute = CachedAttributeExtractor<PropertyTagId, ExifValueUndefinedExtractorAttribute>.Instance.GetAttributeForField(tagId.ToString());

            if (attribute != null)
            {
                return attribute.GetUndefinedExtractor();
            }

            return new SimpleUndefinedExtractor();
        }
        /// <summary>
        /// Gets an IExifPropertyFormatter for the specific tagId
        /// </summary>
        /// <param name="tagId">The Exif Tag Id</param>
        /// <returns>An IExifPropertyFormatter</returns>
        internal static IExifPropertyFormatter GetExifPropertyFormatter(PropertyTagId tagId)
        {
            ExifPropertyFormatterAttribute attribute = CachedAttributeExtractor<PropertyTagId, ExifPropertyFormatterAttribute>.Instance.GetAttributeForField(tagId.ToString());

            if (attribute != null)
            {
                return attribute.ConstructorNeedsPropertyTag ? attribute.GetExifPropertyFormatter(tagId) : attribute.GetExifPropertyFormatter();
            }

            return new SimpleExifPropertyFormatter(tagId);
        }
Пример #4
0
        public object getValueByKey(String valKey)
        {
            PropertyTagId theIndex = (PropertyTagId)Enum.Parse(typeof(PropertyTagId), valKey);

            try
            {
                return((object)imageProps[theIndex].Value);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #5
0
        private string GetExifString(ref Jpeg VtJpeg, string Key)
        {
            PropertyTagId PTagId = GetPIdFromStr(Key);

            if (VtJpeg.ExistPropertyItem(PTagId))
            {
                return(VtJpeg.GetPropertyItemAsString(PTagId));
            }
            else
            {
                return("");
            }
        }
Пример #6
0
        /// <summary>
        /// zapise PropertyItem do obrazku
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public void SetPropertyItem(PropertyTagId TagId, string Text)
        {
            CheckSrcBitmap();

            // ziskani nove instance PropertyItem
            Encoding     EncAscii = Encoding.ASCII;
            PropertyItem NewPItem = CreatePropertyItem(PropertyTagType.ASCII, TagId, Text.Length, EncAscii.GetBytes(Text));

            // zapis do Bitmapy
            if (NewPItem != null)
            {
                SourceBitmap.SetPropertyItem(NewPItem);
            }
        }
Пример #7
0
 // vraci Bitmapu nahledu z exif dat (PropertyTagId.ThumbnailData) nebo null pokud v exifu nic neni
 public Bitmap GetThumbnail()
 {
     foreach (PropertyItem PItem in PropertyItems)
     {
         PropertyTagId PId = (PropertyTagId)(PItem.Id);
         if (PId == PropertyTagId.ThumbnailData)
         {
             MemoryStream MemStream   = new MemoryStream(PItem.Value);
             Bitmap       ThumbBitmap = new Bitmap(MemStream);
             return(ThumbBitmap);
         }
     }
     return(null);
 }
Пример #8
0
 public object this[PropertyTagId TagId]
 {
     get
     {
         try
         {
             PropertyItem property = image.GetPropertyItem((int)TagId);
             return(PropertyTagValue.GetValueObject(property));
         }
         catch
         {
             return(null);
         }
     }
 }
Пример #9
0
        /// <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);
        }
Пример #10
0
        public static void WriteASCIIValue(Vt.Jpeg.Jpeg VtJpeg, string TextValue, PropertyTagId Id)
        {
            // load the image to change
            Image PicImage = new Bitmap(VtJpeg.SourceBitmap);


            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
            EncoderParameters EncParms         = new EncoderParameters(1);
            ImageCodecInfo    CodecInfo        = Vt.Jpeg.Jpeg.GetEncoderInfo("image/jpeg");

            // put the new description into the right property item
            PropertyItem[] PropertyItems = PicImage.PropertyItems;
            PropertyItems[0].Id    = (int)Id; // 0x010e;
            PropertyItems[0].Type  = (short)PropertyTagType.ASCII;
            PropertyItems[0].Len   = TextValue.Length;
            PropertyItems[0].Value = VtStrings.StringToByteArray(TextValue);
            PicImage.SetPropertyItem(PropertyItems[0]);

            // for lossless rewriting must rotate the image by 90 degrees!
            EncoderParameter EncParm = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);

            EncParms.Param[0] = EncParm;

            // ulozim transformovany jpeg do streamu
            MemoryStream TmpStream = new MemoryStream();

            PicImage.Save(TmpStream, CodecInfo, EncParms);
            // vymaz z pameti
            PicImage.Dispose();
            PicImage = null;

            // ted ho otocim zpet a dam do puvodniho souboru
            PicImage          = Image.FromStream(TmpStream);
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate270);
            EncParms.Param[0] = EncParm;
//            PicImage.Save(Filename, CodecInfo, EncParms);
            VtJpeg.LoadFromBitmap(PicImage as Bitmap);


            PicImage.Dispose();
            PicImage = null;
        }
Пример #11
0
        private DateTime GetPreferedDateTime(ref Jpeg VtJpeg, ArrayList PreferExifDate)
        {
            DateTime Result = DateTime.MinValue;

            //foreach (string Item in LBExifDates.Items)
            //{
            //    PropertyTagId PTagId = GetPIdFromStr(Item);
            //    if (VtJpeg.ExistPropertyItem(PTagId))
            //        return VtJpeg.GetPropertyItemAsDateTime(PTagId);
            //}
            foreach (string Item in PreferExifDate)
            {
                PropertyTagId PTagId = GetPIdFromStr(Item);
                if (VtJpeg.ExistPropertyItem(PTagId))
                {
                    return(VtJpeg.GetPropertyItemAsDateTime(PTagId));
                }
            }
            return(Result);
        }
Пример #12
0
        // ziskani DateTime z Exifu
        // data z exifu nelze nejak pretypovat na DateTime, takze pouze parsuju retezec s datumem, pokud se
        // nezadari, tak vracim DateTime.MinValue
        public DateTime GetPropertyItemAsDateTime(PropertyTagId TagId)
        {
            string DateStr = GetPropertyItemAsString(TagId);

            if (DateStr == null)
            {
                return(DateTime.MinValue);
            }
            else
            {
                try
                {
                    DateTime Result = DateTime.ParseExact(DateStr, "yyyy:MM:dd HH:mm:ss", null);
                    return(Result);
                }
                catch
                {
                    return(DateTime.MinValue);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the ExifSubjectDistPropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public ExifSubjectDistPropertyFormatter(PropertyTagId tagId)
     : base(tagId)
 {
 }
Пример #14
0
 ///<summary>Returns the Display Name of a Property Item. The current imlementation will return a name of the Enumeration member.</summary>
 ///<param name="aId">PropertyId to get description for.</param>
 private string getNameFromId(PropertyTagId aId)
 {
     return aId.ToString();
 }
Пример #15
0
        public static object GetImagePropertyValue(Image image, PropertyTagId tagId)
        {
            object result = null;

            PropertyItem propertyItem = null;
            try
            {
                propertyItem = image.GetPropertyItem((int)tagId);
            }
            catch (ArgumentException)
            {
            }

            if (propertyItem != null)
            {
                return GetImagePropertyValue(propertyItem);
            }

            return result;
        }
 /// <summary>
 /// Initializes a new instance of the GenericRational32PropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public GenericRational32PropertyFormatter(PropertyTagId tagId)
     : base(tagId)
 {
 }
Пример #17
0
 public ExifDateTag(PropertyTagId PTagId, bool UseTag)
 {
     this.PTagId = PTagId;
     this.UseTag = UseTag;
 }
Пример #18
0
 /// <summary>
 /// vraci PropertyItem dle ID prevedeny na string
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public string GetPropertyItemAsString(PropertyTagId TagId)
 {
     return(GetPropertyItemAsString((int)TagId));
 }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the SimpleExifPropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public SimpleExifPropertyFormatter(PropertyTagId tagId)
 {
     this.tagId = tagId;
     this.displayNameAttribute = CachedAttributeExtractor<PropertyTagId, EnumDisplayNameAttribute>.Instance.GetAttributeForField(this.tagId.ToString());
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the ExifFNumberPropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public ExifFNumberPropertyFormatter(PropertyTagId tagId)
     : base(tagId)
 {
 }
 /// <summary>
 /// Initializes a new instance of the GpsLatitudeLongitudePropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public GpsLatitudeLongitudePropertyFormatter(PropertyTagId tagId)
     : base(tagId)
 {
 }
Пример #22
0
 /// <summary>
 /// vraci konkretni PropertyItem dle ID
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public PropertyItem GetPropertyItem(PropertyTagId TagId)
 {
     return(GetPropertyItem((int)TagId));
 }
 /// <summary>
 /// Initializes a new instance of the ExifFocalLengthPropertyFormatter class.
 /// </summary>
 /// <param name="tagId">The associated PropertyTagId</param>
 public ExifFocalLengthPropertyFormatter(PropertyTagId tagId)
     : base(tagId)
 {
 }
Пример #24
0
 public bool ExistPropertyItem(PropertyTagId TagId)
 {
     return(GetPropertyItem((int)TagId) != null);
 }
Пример #25
0
 public object this[PropertyTagId TagId]
 {
     get
     {
         try
         {
             PropertyItem property = image.GetPropertyItem((int)TagId);
             return PropertyTagValue.GetValueObject(property);
         }
         catch
         {
             return null;
         }
     }
 }
Пример #26
0
 ///<summary>Returns the Display Name of a Property Item. The current imlementation will return a name of the Enumeration member.</summary>
 ///<param name="aId">PropertyId to get description for.</param>
 private string getNameFromId(PropertyTagId aId)
 {
     return(aId.ToString());
 }
Пример #27
0
        private void CopyPropertyItem(System.Drawing.Image source, System.Drawing.Image destination, PropertyTagId id)
        {
            PropertyItem propItem = source.GetPropertyItem((int)id);

            destination.SetPropertyItem(propItem);

            /*
             * switch (propItem.Type)
             * {
             *  case 1: //Specifies that Value is an array of bytes.
             *      destination.SetPropertyItem(propItem);
             *      break;
             *
             *  case 2: //Specifies that Value is a null-terminated ASCII string. If you set the type data member to ASCII type, you should set the Len property to the length of the string including the null terminator. For example, the string "Hello" would have a length of 6.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 3: //Specifies that Value is an array of unsigned short (16-bit) integers.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 4: //Specifies that Value is an array of unsigned long (32-bit) integers.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 5: //Specifies that Value data member is an array of pairs of unsigned long integers. Each pair represents a fraction; the first integer is the numerator and the second integer is the denominator.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 6: //Specifies that Value is an array of bytes that can hold values of any data type.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 7: //Specifies that Value is an array of signed long (32-bit) integers.
             *      throw new NotImplementedException();
             *      break;
             *
             *  case 10: //Specifies that Value is an array of pairs of signed long integers. Each pair represents a fraction; the first integer is the numerator and the second integer is the denominator.
             *      throw new NotImplementedException();
             *      break;
             *
             * }*/
        }