예제 #1
0
 /// <summary>
 /// This method serves as marsheller of objects for dataset. 
 /// It converts from IPTC octets to relevant java object.
 /// </summary>
 /// <param name="aDirectory">the directory</param>
 /// <param name="aDirectoryType">the directory type</param>
 /// <param name="aTagType">the tag type</param>
 /// <param name="anOffset">the lcOffset</param>
 /// <param name="aTagByteCount">the tag byte count</param>
 private void ProcessTag(
     AbstractDirectory aDirectory,
     int aDirectoryType,
     int aTagType,
     int anOffset,
     int aTagByteCount)
 {
     int tagIdentifier = aTagType | (aDirectoryType << 8);
     switch (tagIdentifier)
     {
         case IptcDirectory.TAG_RECORD_VERSION:
             // short
             short shortValue = (short)((base.data[anOffset] << 8) | base.data[anOffset + 1]);
             aDirectory.SetObject(tagIdentifier, shortValue);
             return;
         case IptcDirectory.TAG_URGENCY:
             // byte
             aDirectory.SetObject(tagIdentifier, base.data[anOffset]);
             return;
         case IptcDirectory.TAG_RELEASE_DATE:
         case IptcDirectory.TAG_DATE_CREATED:
             // Date object
             if (aTagByteCount >= 8)
             {
                 string dateStr = Utils.Decode(base.data, anOffset, aTagByteCount, false);
                 try
                 {
                     int year = Convert.ToInt32(dateStr.Substring(0, 4));
                     int month = Convert.ToInt32(dateStr.Substring(4, 2)); //No -1 here;
                     int day = Convert.ToInt32(dateStr.Substring(6, 2));
                     DateTime date = new DateTime(year, month, day);
                     aDirectory.SetObject(tagIdentifier, date);
                     return;
                 }
                 catch (Exception)
                 {
                     // fall through and we'll store whatever was there as a String
                 }
             }
             break; // Added for .Net compiler
         //case IptcDirectory.TAG_RELEASE_TIME:
         //case IptcDirectory.TAG_TIME_CREATED: 
     }
     // If no special handling by now, treat it as a string
     string str = null;
     if (aTagByteCount < 1)
     {
         str = "";
     }
     else
     {
         str = Utils.Decode(base.data, anOffset, aTagByteCount, false);
     }
     if (aDirectory.ContainsTag(tagIdentifier))
     {
         string[] oldStrings;
         string[] newStrings;
         try
         {
             oldStrings = aDirectory.GetStringArray(tagIdentifier);
         }
         catch (MetadataException)
         {
             oldStrings = null;
         }
         if (oldStrings == null)
         {
             newStrings = new String[1];
         }
         else
         {
             newStrings = new string[oldStrings.Length + 1];
             for (int i = 0; i < oldStrings.Length; i++)
             {
                 newStrings[i] = oldStrings[i];
             }
         }
         newStrings[newStrings.Length - 1] = str;
         aDirectory.SetObject(tagIdentifier, newStrings);
     }
     else
     {
         aDirectory.SetObject(tagIdentifier, str);
     }
 }
예제 #2
0
        /// <summary>
        /// Will stock the thumbnail into exif directory if available.
        /// </summary>
        /// <param name="exifDirectory">where to stock the thumbnail</param>
        /// <param name="tiffHeaderOffset">the tiff lcHeader lcOffset value</param>
        private void StoreThumbnailBytes(AbstractDirectory exifDirectory, int tiffHeaderOffset)
        {
            if (!exifDirectory.ContainsTag(ExifDirectory.TAG_COMPRESSION))
            {
                return;
            }

            if (!exifDirectory.ContainsTag(ExifDirectory.TAG_THUMBNAIL_LENGTH) ||
                !exifDirectory.ContainsTag(ExifDirectory.TAG_THUMBNAIL_OFFSET))
            {
                return;
            }
            try
            {
                int offset = exifDirectory.GetInt(ExifDirectory.TAG_THUMBNAIL_OFFSET);
                int length = exifDirectory.GetInt(ExifDirectory.TAG_THUMBNAIL_LENGTH);
                byte[] result = new byte[length];
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = base.data[tiffHeaderOffset + offset + i];
                }
                exifDirectory.SetObject(ExifDirectory.TAG_THUMBNAIL_DATA, result);
            }
            catch (Exception e)
            {
                exifDirectory.HasError = true;
                Trace.TraceError("Unable to extract thumbnail: " + e.Message);
            }
        }