private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag)
        {
            FITAG value;

            foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS)
            {
                FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value);
                if (mData.IsNull)
                {
                    continue;
                }
                try
                {
                    do
                    {
                        if (value == tag)
                        {
                            return(model);
                        }
                    }while (FreeImage.FindNextMetadata(mData, out value));
                }
                finally
                {
                    if (!mData.IsNull)
                    {
                        FreeImage.FindCloseMetadata(mData);
                    }
                }
            }
            throw new ArgumentException("'tag' is no metadata object of 'dib'");
        }
Exemple #2
0
        /// <summary>
        /// Returns the tag at the given index.
        /// </summary>
        /// <param name="index">Index of the tag to return.</param>
        /// <returns>The tag at the given index.</returns>
        protected MetadataTag GetTagFromIndex(int index)
        {
            if (index >= Count || index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }
            MetadataTag tag;
            int         count    = 0;
            FIMETADATA  mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag);

            if (!mdHandle.IsNull)
            {
                try
                {
                    do
                    {
                        if (count++ == index)
                        {
                            break;
                        }
                    }while (FreeImage.FindNextMetadata(mdHandle, out tag));
                }
                finally
                {
                    FreeImage.FindCloseMetadata(mdHandle);
                }
            }
            return(tag);
        }
 public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag);
 private static extern void FindCloseMetadata_(FIMETADATA mdhandle);
        public void MetadataTag()
        {
            FITAG       tag;
            MetadataTag metaTag;

            Random rand = new Random();

            dib = iManager.GetBitmap(ImageType.Metadata, ImageColorType.Type_01_Dither);
            Assert.IsFalse(dib.IsNull);

            Assert.That(FreeImage.GetMetadataCount(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib) > 0);

            FIMETADATA mData = FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN, dib, out tag);

            Assert.IsFalse(tag.IsNull);
            Assert.IsFalse(mData.IsNull);

            //
            // Constructors
            //

            metaTag = new MetadataTag(tag, dib);
            Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);

            metaTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);
            Assert.That(metaTag.Model == FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN);

            //
            // Properties
            //

            metaTag.ID = ushort.MinValue;
            Assert.That(metaTag.ID == ushort.MinValue);

            metaTag.ID = ushort.MaxValue;
            Assert.That(metaTag.ID == ushort.MaxValue);

            metaTag.ID = ushort.MaxValue / 2;
            Assert.That(metaTag.ID == ushort.MaxValue / 2);

            metaTag.Description = "";
            Assert.That(metaTag.Description == "");

            metaTag.Description = "A";
            Assert.That(metaTag.Description == "A");

            metaTag.Description = "ABCDEFG";
            Assert.That(metaTag.Description == "ABCDEFG");

            metaTag.Key = "";
            Assert.That(metaTag.Key == "");

            metaTag.Key = "A";
            Assert.That(metaTag.Key == "A");

            metaTag.Key = "ABCDEFG";
            Assert.That(metaTag.Key == "ABCDEFG");

            //
            // SetValue
            //

            try
            {
                metaTag.SetValue(null, FREE_IMAGE_MDTYPE.FIDT_ASCII);
                Assert.Fail();
            }
            catch
            {
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_ASCII
            //

            string testString = "";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == 0);

            testString = "X";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == testString.Length);
            Assert.That(((string)metaTag.Value) == testString);

            testString = "TEST-STRING";

            Assert.IsTrue(metaTag.SetValue(testString, FREE_IMAGE_MDTYPE.FIDT_ASCII));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((string)metaTag.Value).Length == testString.Length);
            Assert.That(((string)metaTag.Value) == testString);

            //
            // FREE_IMAGE_MDTYPE.FIDT_BYTE
            //

            byte testByte;

            byte[] testByteArray;

            Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_BYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue);

            Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_BYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testByte      = (byte)rand.Next(byte.MinValue, byte.MaxValue);
                testByteArray = new byte[rand.Next(0, 31)];

                for (int j = 0; j < testByteArray.Length; j++)
                {
                    testByteArray[j] = (byte)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_BYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_BYTE);
                Assert.That(((byte[])metaTag.Value)[0] == testByte);

                Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_BYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length);
                Assert.That(metaTag.Count == testByteArray.Length);
                Assert.That(metaTag.Length == testByteArray.Length * 1);

                byte[] value = (byte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testByteArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_DOUBLE
            //

            double testDouble;

            double[] testDoubleArray;

            Assert.IsTrue(metaTag.SetValue(double.MinValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((double[])metaTag.Value).Length == 1);
            Assert.That(((double[])metaTag.Value)[0] == double.MinValue);

            Assert.IsTrue(metaTag.SetValue(double.MaxValue, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((double[])metaTag.Value).Length == 1);
            Assert.That(((double[])metaTag.Value)[0] == double.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testDouble      = (double)rand.NextDouble();
                testDoubleArray = new double[rand.Next(0, 31)];

                for (int j = 0; j < testDoubleArray.Length; j++)
                {
                    testDoubleArray[j] = rand.NextDouble();
                }

                Assert.IsTrue(metaTag.SetValue(testDouble, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((double[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_DOUBLE);
                Assert.That(((double[])metaTag.Value)[0] == testDouble);

                Assert.IsTrue(metaTag.SetValue(testDoubleArray, FREE_IMAGE_MDTYPE.FIDT_DOUBLE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((double[])metaTag.Value).Length == testDoubleArray.Length);
                Assert.That(metaTag.Count == testDoubleArray.Length);
                Assert.That(metaTag.Length == testDoubleArray.Length * 8);

                double[] value = (double[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testDoubleArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_FLOAT
            //

            float testfloat;

            float[] testFloatArray;

            Assert.IsTrue(metaTag.SetValue(float.MinValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((float[])metaTag.Value).Length == 1);
            Assert.That(((float[])metaTag.Value)[0] == float.MinValue);

            Assert.IsTrue(metaTag.SetValue(float.MaxValue, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((float[])metaTag.Value).Length == 1);
            Assert.That(((float[])metaTag.Value)[0] == float.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testfloat      = (float)rand.NextDouble();
                testFloatArray = new float[rand.Next(0, 31)];

                for (int j = 0; j < testFloatArray.Length; j++)
                {
                    testFloatArray[j] = (float)rand.NextDouble();
                }

                Assert.IsTrue(metaTag.SetValue(testfloat, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((float[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_FLOAT);
                Assert.That(((float[])metaTag.Value)[0] == testfloat);

                Assert.IsTrue(metaTag.SetValue(testFloatArray, FREE_IMAGE_MDTYPE.FIDT_FLOAT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((float[])metaTag.Value).Length == testFloatArray.Length);
                Assert.That(metaTag.Count == testFloatArray.Length);
                Assert.That(metaTag.Length == testFloatArray.Length * 4);

                float[] value = (float[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testFloatArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_IFD
            //

            uint testUint;

            uint[] testUintArray;

            Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_IFD));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue);

            Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_IFD));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUint      = (uint)rand.NextDouble();
                testUintArray = new uint[rand.Next(0, 31)];

                for (int j = 0; j < testUintArray.Length; j++)
                {
                    testUintArray[j] = (uint)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_IFD));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_IFD);
                Assert.That(((uint[])metaTag.Value)[0] == testUint);

                Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_IFD));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length);
                Assert.That(metaTag.Count == testUintArray.Length);
                Assert.That(metaTag.Length == testUintArray.Length * 4);

                uint[] value = (uint[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testUintArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_LONG
            //

            Assert.IsTrue(metaTag.SetValue(uint.MinValue, FREE_IMAGE_MDTYPE.FIDT_LONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MinValue);

            Assert.IsTrue(metaTag.SetValue(uint.MaxValue, FREE_IMAGE_MDTYPE.FIDT_LONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((uint[])metaTag.Value).Length == 1);
            Assert.That(((uint[])metaTag.Value)[0] == uint.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUint      = (uint)rand.NextDouble();
                testUintArray = new uint[rand.Next(0, 31)];

                for (int j = 0; j < testUintArray.Length; j++)
                {
                    testUintArray[j] = (uint)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testUint, FREE_IMAGE_MDTYPE.FIDT_LONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_LONG);
                Assert.That(((uint[])metaTag.Value)[0] == testUint);

                Assert.IsTrue(metaTag.SetValue(testUintArray, FREE_IMAGE_MDTYPE.FIDT_LONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((uint[])metaTag.Value).Length == testUintArray.Length);
                Assert.That(metaTag.Count == testUintArray.Length);
                Assert.That(metaTag.Length == testUintArray.Length * 4);

                uint[] value = (uint[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testUintArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_NOTYPE
            //

            try
            {
                metaTag.SetValue(new object(), FREE_IMAGE_MDTYPE.FIDT_NOTYPE);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_PALETTE
            //

            RGBQUAD testRGBQUAD;

            RGBQUAD[] testRGBQUADArray;

            for (int i = 0; i < 10; i++)
            {
                testRGBQUAD      = new RGBQUAD(Color.FromArgb(rand.Next()));
                testRGBQUADArray = new RGBQUAD[rand.Next(0, 31)];

                for (int j = 0; j < testRGBQUADArray.Length; j++)
                {
                    testRGBQUADArray[j] = new RGBQUAD(Color.FromArgb(rand.Next()));
                }

                Assert.IsTrue(metaTag.SetValue(testRGBQUAD, FREE_IMAGE_MDTYPE.FIDT_PALETTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((RGBQUAD[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_PALETTE);
                Assert.That(((RGBQUAD[])metaTag.Value)[0] == testRGBQUAD);

                Assert.IsTrue(metaTag.SetValue(testRGBQUADArray, FREE_IMAGE_MDTYPE.FIDT_PALETTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((RGBQUAD[])metaTag.Value).Length == testRGBQUADArray.Length);
                Assert.That(metaTag.Count == testRGBQUADArray.Length);
                Assert.That(metaTag.Length == testRGBQUADArray.Length * 4);

                RGBQUAD[] value = (RGBQUAD[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testRGBQUADArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_RATIONAL
            //

            FIURational testFIURational;

            FIURational[] testFIURationalArray;

            for (int i = 0; i < 10; i++)
            {
                testFIURational      = new FIURational((uint)rand.Next(), (uint)rand.Next());
                testFIURationalArray = new FIURational[rand.Next(0, 31)];

                for (int j = 0; j < testFIURationalArray.Length; j++)
                {
                    testFIURationalArray[j] = new FIURational((uint)rand.Next(), (uint)rand.Next());
                }

                Assert.IsTrue(metaTag.SetValue(testFIURational, FREE_IMAGE_MDTYPE.FIDT_RATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIURational[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_RATIONAL);
                Assert.That(((FIURational[])metaTag.Value)[0] == testFIURational);

                Assert.IsTrue(metaTag.SetValue(testFIURationalArray, FREE_IMAGE_MDTYPE.FIDT_RATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIURational[])metaTag.Value).Length == testFIURationalArray.Length);
                Assert.That(metaTag.Count == testFIURationalArray.Length);
                Assert.That(metaTag.Length == testFIURationalArray.Length * 8);

                FIURational[] value = (FIURational[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testFIURationalArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SBYTE
            //

            sbyte testSByte;

            sbyte[] testSByteArray;

            Assert.IsTrue(metaTag.SetValue(sbyte.MinValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((sbyte[])metaTag.Value).Length == 1);
            Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MinValue);

            Assert.IsTrue(metaTag.SetValue(sbyte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((sbyte[])metaTag.Value).Length == 1);
            Assert.That(((sbyte[])metaTag.Value)[0] == sbyte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testSByte      = (sbyte)rand.Next(sbyte.MinValue, sbyte.MaxValue);
                testSByteArray = new sbyte[rand.Next(0, 31)];

                for (int j = 0; j < testSByteArray.Length; j++)
                {
                    testSByteArray[j] = (sbyte)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testSByte, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((sbyte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SBYTE);
                Assert.That(((sbyte[])metaTag.Value)[0] == testSByte);

                Assert.IsTrue(metaTag.SetValue(testSByteArray, FREE_IMAGE_MDTYPE.FIDT_SBYTE));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((sbyte[])metaTag.Value).Length == testSByteArray.Length);
                Assert.That(metaTag.Count == testSByteArray.Length);
                Assert.That(metaTag.Length == testSByteArray.Length * 1);

                sbyte[] value = (sbyte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testSByteArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SHORT
            //

            ushort testUShort;

            ushort[] testUShortArray;

            Assert.IsTrue(metaTag.SetValue(ushort.MinValue, FREE_IMAGE_MDTYPE.FIDT_SHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((ushort[])metaTag.Value).Length == 1);
            Assert.That(((ushort[])metaTag.Value)[0] == ushort.MinValue);

            Assert.IsTrue(metaTag.SetValue(ushort.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((ushort[])metaTag.Value).Length == 1);
            Assert.That(((ushort[])metaTag.Value)[0] == ushort.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testUShort      = (ushort)rand.Next(ushort.MinValue, sbyte.MaxValue);
                testUShortArray = new ushort[rand.Next(0, 31)];

                for (int j = 0; j < testUShortArray.Length; j++)
                {
                    testUShortArray[j] = (ushort)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testUShort, FREE_IMAGE_MDTYPE.FIDT_SHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((ushort[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 2);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SHORT);
                Assert.That(((ushort[])metaTag.Value)[0] == testUShort);

                Assert.IsTrue(metaTag.SetValue(testUShortArray, FREE_IMAGE_MDTYPE.FIDT_SHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((ushort[])metaTag.Value).Length == testUShortArray.Length);
                Assert.That(metaTag.Count == testUShortArray.Length);
                Assert.That(metaTag.Length == testUShortArray.Length * 2);

                ushort[] value = (ushort[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testUShortArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SLONG
            //

            int testInt;

            int[] testIntArray;

            Assert.IsTrue(metaTag.SetValue(int.MinValue, FREE_IMAGE_MDTYPE.FIDT_SLONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((int[])metaTag.Value).Length == 1);
            Assert.That(((int[])metaTag.Value)[0] == int.MinValue);

            Assert.IsTrue(metaTag.SetValue(int.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SLONG));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((int[])metaTag.Value).Length == 1);
            Assert.That(((int[])metaTag.Value)[0] == int.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testInt      = (int)rand.NextDouble();
                testIntArray = new int[rand.Next(0, 31)];

                for (int j = 0; j < testIntArray.Length; j++)
                {
                    testIntArray[j] = rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testInt, FREE_IMAGE_MDTYPE.FIDT_SLONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((int[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 4);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SLONG);
                Assert.That(((int[])metaTag.Value)[0] == testInt);

                Assert.IsTrue(metaTag.SetValue(testIntArray, FREE_IMAGE_MDTYPE.FIDT_SLONG));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((int[])metaTag.Value).Length == testIntArray.Length);
                Assert.That(metaTag.Count == testIntArray.Length);
                Assert.That(metaTag.Length == testIntArray.Length * 4);

                int[] value = (int[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testIntArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SRATIONAL
            //

            FIRational testFIRational;

            FIRational[] testFIRationalArray;

            for (int i = 0; i < 10; i++)
            {
                testFIRational      = new FIRational(rand.Next(), rand.Next());
                testFIRationalArray = new FIRational[rand.Next(0, 31)];

                for (int j = 0; j < testFIRationalArray.Length; j++)
                {
                    testFIRationalArray[j] = new FIRational(rand.Next(), rand.Next());
                }

                Assert.IsTrue(metaTag.SetValue(testFIRational, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIRational[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 8);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SRATIONAL);
                Assert.That(((FIRational[])metaTag.Value)[0] == testFIRational);

                Assert.IsTrue(metaTag.SetValue(testFIRationalArray, FREE_IMAGE_MDTYPE.FIDT_SRATIONAL));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((FIRational[])metaTag.Value).Length == testFIRationalArray.Length);
                Assert.That(metaTag.Count == testFIRationalArray.Length);
                Assert.That(metaTag.Length == testFIRationalArray.Length * 8);

                FIRational[] value = (FIRational[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testFIRationalArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_SSHORT
            //

            short testShort;

            short[] testShortArray;

            Assert.IsTrue(metaTag.SetValue(short.MinValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((short[])metaTag.Value).Length == 1);
            Assert.That(((short[])metaTag.Value)[0] == short.MinValue);

            Assert.IsTrue(metaTag.SetValue(short.MaxValue, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((short[])metaTag.Value).Length == 1);
            Assert.That(((short[])metaTag.Value)[0] == short.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testShort      = (short)rand.Next(short.MinValue, short.MaxValue);
                testShortArray = new short[rand.Next(0, 31)];

                for (int j = 0; j < testShortArray.Length; j++)
                {
                    testShortArray[j] = (short)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testShort, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((short[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 2);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_SSHORT);
                Assert.That(((short[])metaTag.Value)[0] == testShort);

                Assert.IsTrue(metaTag.SetValue(testShortArray, FREE_IMAGE_MDTYPE.FIDT_SSHORT));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((short[])metaTag.Value).Length == testShortArray.Length);
                Assert.That(metaTag.Count == testShortArray.Length);
                Assert.That(metaTag.Length == testShortArray.Length * 2);

                short[] value = (short[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testShortArray[j] == value[j]);
                }
            }

            //
            // FREE_IMAGE_MDTYPE.FIDT_UNDEFINED
            //

            Assert.IsTrue(metaTag.SetValue(byte.MinValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MinValue);

            Assert.IsTrue(metaTag.SetValue(byte.MaxValue, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
            Assert.IsNotNull(metaTag.Value);
            Assert.That(((byte[])metaTag.Value).Length == 1);
            Assert.That(((byte[])metaTag.Value)[0] == byte.MaxValue);

            for (int i = 0; i < 10; i++)
            {
                testByte      = (byte)rand.Next(byte.MinValue, byte.MaxValue);
                testByteArray = new byte[rand.Next(0, 31)];

                for (int j = 0; j < testByteArray.Length; j++)
                {
                    testByteArray[j] = (byte)rand.Next();
                }

                Assert.IsTrue(metaTag.SetValue(testByte, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == 1);
                Assert.That(metaTag.Count == 1);
                Assert.That(metaTag.Length == 1);
                Assert.That(metaTag.Type == FREE_IMAGE_MDTYPE.FIDT_UNDEFINED);
                Assert.That(((byte[])metaTag.Value)[0] == testByte);

                Assert.IsTrue(metaTag.SetValue(testByteArray, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED));
                Assert.IsNotNull(metaTag.Value);
                Assert.That(((byte[])metaTag.Value).Length == testByteArray.Length);
                Assert.That(metaTag.Count == testByteArray.Length);
                Assert.That(metaTag.Length == testByteArray.Length * 1);

                byte[] value = (byte[])metaTag.Value;

                for (int j = 0; j < value.Length; j++)
                {
                    Assert.That(testByteArray[j] == value[j]);
                }
            }

            FreeImage.UnloadEx(ref dib);
        }
 /// <summary>
 /// Find the next tag, if any, that matches the metadata model argument in a previous call
 /// to FindFirstMetadata, and then alters the tag object contents accordingly.
 /// </summary>
 /// <param name="mdhandle">Unique search handle provided by FindFirstMetadata.</param>
 /// <param name="tag">Tag that matches the metadata model.</param>
 /// <returns>Returns true on success, false on failure.</returns>
 public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag)
 {
     FITAG _tag;
     bool result;
     if (FindNextMetadata(mdhandle, out _tag))
     {
         tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]);
         result = true;
     }
     else
     {
         tag = null;
         result = false;
     }
     return result;
 }
 /// <summary>
 /// Closes the specified metadata search handle and releases associated resources.
 /// </summary>
 /// <param name="mdhandle">The handle to close.</param>
 public static void FindCloseMetadata(FIMETADATA mdhandle)
 {
     if (metaDataSearchHandler.ContainsKey(mdhandle))
     {
         metaDataSearchHandler.Remove(mdhandle);
     }
     FindCloseMetadata_(mdhandle);
 }