예제 #1
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);
            }
            }
        }
예제 #2
0
        public static ImageData CreateJbig2(byte[] bytes, int page)
        {
            if (page < 1)
            {
                throw new ArgumentException("The page number must be greater than 0");
            }
            ValidateImageType(bytes, ImageType.JBIG2);
            ImageData image = new Jbig2ImageData(bytes, page);

            Jbig2ImageHelper.ProcessImage(image);
            return(image);
        }
예제 #3
0
 public static ImageData CreateJbig2(byte[] bytes, int page)
 {
     if (page < 1)
     {
         throw new ArgumentException("The page number must be greater than 0");
     }
     byte[] imageType = ReadImageType(bytes);
     if (ImageTypeIs(imageType, jbig2))
     {
         ImageData image = new Jbig2ImageData(bytes, page);
         Jbig2ImageHelper.ProcessImage(image);
         return(image);
     }
     throw new ArgumentException("JBIG2 image expected.");
 }
예제 #4
0
        public static void ProcessImage(ImageData jbig2)
        {
            if (jbig2.GetOriginalType() != ImageType.JBIG2)
            {
                throw new ArgumentException("JBIG2 image expected");
            }
            Jbig2ImageData image = (Jbig2ImageData)jbig2;

            try {
                IRandomAccessSource ras;
                if (image.GetData() == null)
                {
                    image.LoadData();
                }
                ras = new RandomAccessSourceFactory().CreateSource(image.GetData());
                RandomAccessFileOrArray raf = new RandomAccessFileOrArray(ras);
                Jbig2SegmentReader      sr  = new Jbig2SegmentReader(raf);
                sr.Read();
                Jbig2SegmentReader.Jbig2Page p = sr.GetPage(image.GetPage());
                raf.Close();
                image.SetHeight(p.pageBitmapHeight);
                image.SetWidth(p.pageBitmapWidth);
                image.SetBpc(1);
                image.SetColorSpace(1);
                //TODO JBIG2 globals caching
                byte[] globals = sr.GetGlobal(true);
                //TODO due to the fact, that streams now may be transformed to indirect objects only on writing,
                //pdfStream.getDocument() cannot longer be the sign of inline/indirect images
                // in case inline image pdfStream.getDocument() will be null
                if (globals != null)
                {
                    /*&& stream.getDocument() != null*/
                    IDictionary <String, Object> decodeParms = new Dictionary <String, Object>();
                    //                PdfStream globalsStream = new PdfStream().makeIndirect(pdfStream.getDocument());
                    //                globalsStream.getOutputStream().write(globals);
                    decodeParms["JBIG2Globals"] = globals;
                    image.decodeParms           = decodeParms;
                }
                image.SetFilter("JBIG2Decode");
                image.SetColorSpace(1);
                image.SetBpc(1);
                image.data = p.GetData(true);
            }
            catch (System.IO.IOException e) {
                throw new iText.IO.IOException(iText.IO.IOException.Jbig2ImageException, e);
            }
        }
예제 #5
0
 private static ImageData CreateImageInstance(byte[] bytes, bool recoverImage)
 {
     byte[] imageType = ReadImageType(bytes);
     if (ImageTypeIs(imageType, gif))
     {
         GifImageData image = new GifImageData(bytes);
         GifImageHelper.ProcessImage(image, 0);
         return(image.GetFrames()[0]);
     }
     else
     {
         if (ImageTypeIs(imageType, jpeg))
         {
             ImageData image = new JpegImageData(bytes);
             JpegImageHelper.ProcessImage(image);
             return(image);
         }
         else
         {
             if (ImageTypeIs(imageType, jpeg2000_1) || ImageTypeIs(imageType, jpeg2000_2))
             {
                 ImageData image = new Jpeg2000ImageData(bytes);
                 Jpeg2000ImageHelper.ProcessImage(image);
                 return(image);
             }
             else
             {
                 if (ImageTypeIs(imageType, png))
                 {
                     ImageData image = new PngImageData(bytes);
                     PngImageHelper.ProcessImage(image);
                     return(image);
                 }
                 else
                 {
                     if (ImageTypeIs(imageType, bmp))
                     {
                         ImageData image = new BmpImageData(bytes, false, 0);
                         BmpImageHelper.ProcessImage(image);
                         return(image);
                     }
                     else
                     {
                         if (ImageTypeIs(imageType, tiff_1) || ImageTypeIs(imageType, tiff_2))
                         {
                             ImageData image = new TiffImageData(bytes, recoverImage, 1, false);
                             TiffImageHelper.ProcessImage(image);
                             return(image);
                         }
                         else
                         {
                             if (ImageTypeIs(imageType, jbig2))
                             {
                                 ImageData image = new Jbig2ImageData(bytes, 1);
                                 Jbig2ImageHelper.ProcessImage(image);
                                 return(image);
                             }
                         }
                     }
                 }
             }
         }
     }
     throw new iText.IO.IOException(iText.IO.IOException.ImageFormatCannotBeRecognized);
 }