Example #1
0
        /**
         *  Constructor used to attach images to existing PDF.
         *
         *  @param pdf the page to draw this image on.
         *  @param inputStream the input stream to read the image from.
         *  @param imageType ImageType.JPG, ImageType.PNG and ImageType.BMP.
         *
         */
        public Image(SortedDictionary <Int32, PDFobj> objects, Stream inputStream, int imageType)
        {
            byte[] data;
            if (imageType == ImageType.JPG)
            {
                JPGImage jpg = new JPGImage(inputStream);
                data = jpg.GetData();
                w    = jpg.GetWidth();
                h    = jpg.GetHeight();
                if (jpg.GetColorComponents() == 1)
                {
                    AddImage(objects, data, null, imageType, "DeviceGray", 8);
                }
                else if (jpg.GetColorComponents() == 3)
                {
                    AddImage(objects, data, null, imageType, "DeviceRGB", 8);
                }
                else if (jpg.GetColorComponents() == 4)
                {
                    AddImage(objects, data, null, imageType, "DeviceCMYK", 8);
                }
            }
            else if (imageType == ImageType.PNG)
            {
                PNGImage png = new PNGImage(inputStream);
                data = png.GetData();
                w    = png.GetWidth();
                h    = png.GetHeight();
                if (png.GetColorType() == 0)
                {
                    AddImage(objects, data, null, imageType, "DeviceGray", png.GetBitDepth());
                }
                else
                {
                    if (png.GetBitDepth() == 16)
                    {
                        AddImage(objects, data, null, imageType, "DeviceRGB", 16);
                    }
                    else
                    {
                        AddImage(objects, data, png.GetAlpha(), imageType, "DeviceRGB", 8);
                    }
                }
            }
            else if (imageType == ImageType.BMP)
            {
                BMPImage bmp = new BMPImage(inputStream);
                data = bmp.GetData();
                w    = bmp.GetWidth();
                h    = bmp.GetHeight();
                AddImage(objects, data, null, imageType, "DeviceRGB", 8);
            }

/*
 *      else if (imageType == ImageType.JET) {
 *          AddImage(pdf, inputStream);
 *      }
 */
            inputStream.Close();
        }
Example #2
0
        /**
         *  The main constructor for the Image class.
         *
         *  @param pdf the page to draw this image on.
         *  @param inputStream the input stream to read the image from.
         *  @param imageType ImageType.JPG, ImageType.PNG or ImageType.BMP.
         *
         */
        public Image(PDF pdf, Stream inputStream, int imageType)
        {
            byte[] data;
            if (imageType == ImageType.JPG)
            {
                JPGImage jpg = new JPGImage(inputStream);
                data = jpg.GetData();
                w    = jpg.GetWidth();
                h    = jpg.GetHeight();
                if (jpg.GetColorComponents() == 1)
                {
                    AddImage(pdf, data, null, imageType, "DeviceGray", 8);
                }
                else if (jpg.GetColorComponents() == 3)
                {
                    AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
                }
                else if (jpg.GetColorComponents() == 4)
                {
                    AddImage(pdf, data, null, imageType, "DeviceCMYK", 8);
                }
            }
            else if (imageType == ImageType.PNG)
            {
                PNGImage png = new PNGImage(inputStream);
                data = png.GetData();
                w    = png.GetWidth();
                h    = png.GetHeight();
                if (png.GetColorType() == 0)
                {
                    AddImage(pdf, data, null, imageType, "DeviceGray", png.GetBitDepth());
                }
                else
                {
                    if (png.GetBitDepth() == 16)
                    {
                        AddImage(pdf, data, null, imageType, "DeviceRGB", 16);
                    }
                    else
                    {
                        AddImage(pdf, data, png.GetAlpha(), imageType, "DeviceRGB", 8);
                    }
                }
            }
            else if (imageType == ImageType.BMP)
            {
                BMPImage bmp = new BMPImage(inputStream);
                data = bmp.GetData();
                w    = bmp.GetWidth();
                h    = bmp.GetHeight();
                AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
            }
            else if (imageType == ImageType.PNG_STREAM)
            {
                AddImage(pdf, inputStream);
            }

            inputStream.Dispose();
        }
Example #3
0
 public Image(PDF pdf, Stream inputStream, int imageType)
 {
     if (imageType == ImageType.JPG)
     {
         JPGImage jPGImage = new JPGImage(inputStream);
         byte[]   data     = jPGImage.GetData();
         this.w = (float)jPGImage.GetWidth();
         this.h = (float)jPGImage.GetHeight();
         if (jPGImage.GetColorComponents() == 1)
         {
             this.AddImage(pdf, data, null, imageType, "DeviceGray", 8);
         }
         else
         {
             if (jPGImage.GetColorComponents() == 3)
             {
                 this.AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
             }
             else
             {
                 if (jPGImage.GetColorComponents() == 4)
                 {
                     this.AddImage(pdf, data, null, imageType, "DeviceCMYK", 8);
                 }
             }
         }
     }
     else
     {
         if (imageType == ImageType.PNG)
         {
             PNGImage pNGImage = new PNGImage(inputStream);
             byte[]   data     = pNGImage.GetData();
             this.w = (float)pNGImage.GetWidth();
             this.h = (float)pNGImage.GetHeight();
             if (pNGImage.colorType == 0)
             {
                 this.AddImage(pdf, data, null, imageType, "DeviceGray", (int)pNGImage.bitDepth);
             }
             else
             {
                 if (pNGImage.bitDepth == 16)
                 {
                     this.AddImage(pdf, data, null, imageType, "DeviceRGB", 16);
                 }
                 else
                 {
                     this.AddImage(pdf, data, pNGImage.GetAlpha(), imageType, "DeviceRGB", 8);
                 }
             }
         }
         else
         {
             if (imageType == ImageType.BMP)
             {
                 BMPImage bMPImage = new BMPImage(inputStream);
                 byte[]   data     = bMPImage.GetData();
                 this.w = (float)bMPImage.GetWidth();
                 this.h = (float)bMPImage.GetHeight();
                 this.AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
             }
         }
     }
     inputStream.Dispose();
 }
Example #4
0
        /**
         *  The main constructor for the Image class.
         *
         *  @param pdf the page to draw this image on.
         *  @param inputStream the input stream to read the image from.
         *  @param imageType ImageType.JPG, ImageType.PNG or ImageType.BMP.
         *
         */
        public Image(PDF pdf, Stream inputStream, int imageType)
        {
            byte[] data;
            if (imageType == ImageType.JPG) {
            JPGImage jpg = new JPGImage(inputStream);
            data = jpg.GetData();
            w = jpg.GetWidth();
            h = jpg.GetHeight();
            if (jpg.GetColorComponents() == 1) {
                AddImage(pdf, data, null, imageType, "DeviceGray", 8);
            }
            else if (jpg.GetColorComponents() == 3) {
                AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
            }
            else if (jpg.GetColorComponents() == 4) {
                AddImage(pdf, data, null, imageType, "DeviceCMYK", 8);
            }
            }
            else if (imageType == ImageType.PNG) {
            PNGImage png = new PNGImage(inputStream);
            data = png.GetData();
            w = png.GetWidth();
            h = png.GetHeight();
            if (png.GetColorType() == 0) {
                AddImage(pdf, data, null, imageType, "DeviceGray", png.GetBitDepth());
            }
            else {
                if (png.GetBitDepth() == 16) {
                    AddImage(pdf, data, null, imageType, "DeviceRGB", 16);
                }
                else {
                    AddImage(pdf, data, png.GetAlpha(), imageType, "DeviceRGB", 8);
                }
            }
            }
            else if (imageType == ImageType.BMP) {
            BMPImage bmp = new BMPImage(inputStream);
            data = bmp.GetData();
            w = bmp.GetWidth();
            h = bmp.GetHeight();
            AddImage(pdf, data, null, imageType, "DeviceRGB", 8);
            }
            else if (imageType == ImageType.JET) {
            AddImage(pdf, inputStream);
            }

            inputStream.Dispose();
        }