Exemple #1
0
        private static void ValidateImageType(Uri imageUrl, ImageType expectedType)
        {
            ImageType detectedType = ImageTypeDetector.DetectImageType(imageUrl);

            if (detectedType != expectedType)
            {
                throw new ArgumentException(expectedType.ToString() + " image expected. Detected image type: " + detectedType
                                            .ToString());
            }
        }
Exemple #2
0
        /// <summary>Checks if the type of image (based on first 8 bytes) is supported by factory.</summary>
        /// <remarks>
        /// Checks if the type of image (based on first 8 bytes) is supported by factory.
        /// <br />
        /// <b>Note:</b> if this method returns
        /// <see langword="true"/>
        /// it doesn't means that
        /// <see cref="Create(byte[])"/>
        /// won't throw exception
        /// </remarks>
        /// <param name="source">image URL</param>
        /// <returns>
        ///
        /// <see langword="true"/>
        /// if first eight bytes are recognised by factory as valid image type and
        /// <see langword="false"/>
        /// otherwise
        /// </returns>
        public static bool IsSupportedType(Uri source)
        {
            if (source == null)
            {
                return(false);
            }
            ImageType imageType = ImageTypeDetector.DetectImageType(source);

            return(IsSupportedType(imageType));
        }
Exemple #3
0
 public static ImageData CreateBmp(byte[] bytes, bool noHeader, int size)
 {
     if (noHeader || ImageTypeDetector.DetectImageType(bytes) == ImageType.BMP)
     {
         ImageData image = new BmpImageData(bytes, noHeader, size);
         BmpImageHelper.ProcessImage(image);
         return(image);
     }
     throw new ArgumentException("BMP image expected.");
 }
Exemple #4
0
        private static ImageData CreateImageInstance(byte[] bytes, bool recoverImage)
        {
            ImageType imageType = ImageTypeDetector.DetectImageType(bytes);

            switch (imageType)
            {
            case ImageType.GIF: {
                GifImageData image = new GifImageData(bytes);
                GifImageHelper.ProcessImage(image, 0);
                return(image.GetFrames()[0]);
            }

            case ImageType.JPEG: {
                ImageData image = new JpegImageData(bytes);
                JpegImageHelper.ProcessImage(image);
                return(image);
            }

            case ImageType.JPEG2000: {
                ImageData image = new Jpeg2000ImageData(bytes);
                Jpeg2000ImageHelper.ProcessImage(image);
                return(image);
            }

            case ImageType.PNG: {
                ImageData image = new PngImageData(bytes);
                PngImageHelper.ProcessImage(image);
                return(image);
            }

            case ImageType.BMP: {
                ImageData image = new BmpImageData(bytes, false);
                BmpImageHelper.ProcessImage(image);
                return(image);
            }

            case ImageType.TIFF: {
                ImageData image = new TiffImageData(bytes, recoverImage, 1, false);
                TiffImageHelper.ProcessImage(image);
                return(image);
            }

            case ImageType.JBIG2: {
                ImageData image = new Jbig2ImageData(bytes, 1);
                Jbig2ImageHelper.ProcessImage(image);
                return(image);
            }

            default: {
                throw new iText.IO.IOException(iText.IO.IOException.ImageFormatCannotBeRecognized);
            }
            }
        }
Exemple #5
0
 private void Test(Uri location, ImageType expectedType)
 {
     NUnit.Framework.Assert.AreEqual(expectedType, ImageTypeDetector.DetectImageType(location));
 }