Beispiel #1
0
 /// <summary>
 /// Performs the Jfif data extraction, adding found values to the specified
 /// instance of
 /// <see cref="Com.Drew.Metadata.Metadata"/>
 /// .
 /// </summary>
 public virtual void Extract([NotNull] RandomAccessReader reader, [NotNull] Com.Drew.Metadata.Metadata metadata)
 {
     JfifDirectory directory = new JfifDirectory();
     metadata.AddDirectory(directory);
     try
     {
         // For JFIF, the tag number is also the offset into the segment
         int ver = reader.GetUInt16(JfifDirectory.TagVersion);
         directory.SetInt(JfifDirectory.TagVersion, ver);
         int units = reader.GetUInt8(JfifDirectory.TagUnits);
         directory.SetInt(JfifDirectory.TagUnits, units);
         int height = reader.GetUInt16(JfifDirectory.TagResx);
         directory.SetInt(JfifDirectory.TagResx, height);
         int width = reader.GetUInt16(JfifDirectory.TagResy);
         directory.SetInt(JfifDirectory.TagResy, width);
     }
     catch (IOException me)
     {
         directory.AddError(me.Message);
     }
 }
        /// <summary>
        /// Performs the Jfif data extraction, adding found values to the specified
        /// instance of
        /// <see cref="Com.Drew.Metadata.Metadata"/>
        /// .
        /// </summary>
        public virtual void Extract(RandomAccessReader reader, Com.Drew.Metadata.Metadata metadata)
        {
            JfifDirectory directory = metadata.GetOrCreateDirectory <JfifDirectory>();

            try
            {
                // For JFIF, the tag number is also the offset into the segment
                int ver = reader.GetUInt16(JfifDirectory.TagVersion);
                directory.SetInt(JfifDirectory.TagVersion, ver);
                int units = reader.GetUInt8(JfifDirectory.TagUnits);
                directory.SetInt(JfifDirectory.TagUnits, units);
                int height = reader.GetUInt16(JfifDirectory.TagResx);
                directory.SetInt(JfifDirectory.TagResx, height);
                int width = reader.GetUInt16(JfifDirectory.TagResy);
                directory.SetInt(JfifDirectory.TagResy, width);
            }
            catch (IOException me)
            {
                directory.AddError(me.Message);
            }
        }
        public virtual void TestRead()
        {
            sbyte[] jfifData = new sbyte[] { 74, 70, 73, 70, 0, 1, 2, 1, 0, 108, 0, 108, 0, 0 };
            Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
            JfifReader reader = new JfifReader();

            reader.Extract(new ByteArrayReader(jfifData), metadata);
            Sharpen.Tests.AreEqual(1, metadata.GetDirectoryCount());
            JfifDirectory directory = metadata.GetFirstDirectoryOfType <JfifDirectory>();

            NUnit.Framework.Assert.IsNotNull(directory);
            Sharpen.Tests.IsFalse(Sharpen.Extensions.ConvertToString(directory.GetErrors()), directory.HasErrors());
            Tag[] tags = Sharpen.Collections.ToArray(directory.GetTags(), new Tag[directory.GetTagCount()]);
            Sharpen.Tests.AreEqual(4, tags.Length);
            Sharpen.Tests.AreEqual(JfifDirectory.TagVersion, tags[0].GetTagType());
            Sharpen.Tests.AreEqual(unchecked ((int)(0x0102)), directory.GetInt(tags[0].GetTagType()));
            Sharpen.Tests.AreEqual(JfifDirectory.TagUnits, tags[1].GetTagType());
            Sharpen.Tests.AreEqual(1, directory.GetInt(tags[1].GetTagType()));
            Sharpen.Tests.AreEqual(JfifDirectory.TagResx, tags[2].GetTagType());
            Sharpen.Tests.AreEqual(108, directory.GetInt(tags[2].GetTagType()));
            Sharpen.Tests.AreEqual(JfifDirectory.TagResy, tags[3].GetTagType());
            Sharpen.Tests.AreEqual(108, directory.GetInt(tags[3].GetTagType()));
        }