예제 #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();
        }
예제 #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();
        }
예제 #3
0
        public Image(PDF pdf, System.IO.Stream inputStream, int imageType)
        {
            if (imageType == ImageType.JPEG)
            {
                JPEGImage jpg = new JPEGImage(inputStream);
                data = jpg.GetData();
                w    = jpg.GetWidth();
                h    = jpg.GetHeight();
                if (jpg.GetColorComponents() == 1)
                {
                    addImage(pdf, data, imageType, "DeviceGray", 8);
                }
                else if (jpg.GetColorComponents() == 3)
                {
                    addImage(pdf, data, imageType, "DeviceRGB", 8);
                }
            }
            else if (imageType == ImageType.PNG)
            {
                PNGImage png = new PNGImage(inputStream);
                data = png.GetData();
                w    = png.GetWidth();
                h    = png.GetHeight();
                if (png.colorType == 0)
                {
                    addImage(pdf, data, imageType, "DeviceGray", png.bitDepth);
                }
                else
                {
                    if (png.bitDepth == 16)
                    {
                        addImage(pdf, data, imageType, "DeviceRGB", 16);
                    }
                    else
                    {
                        addImage(pdf, data, 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, imageType, "DeviceRGB", 8);
            }

            inputStream.Close();
        }
예제 #4
0
파일: Image.cs 프로젝트: Jackjet/ECOSingle
 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();
 }
예제 #5
0
파일: Image.cs 프로젝트: lubota/spartacus
        /**
         *  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();
        }
예제 #6
0
        private void parseData(Stream stream)
        {
            this.image = new byte[this.w * this.h * 3];
            int length = 4 * (int)Math.Ceiling((double)(this.bpp * this.w) / 32.0);

            try
            {
                int i = 0;
                while (i < this.h)
                {
                    byte[] array = this.getBytes(stream, length);
                    int    num   = this.bpp;
                    if (num <= 8)
                    {
                        if (num != 1)
                        {
                            if (num != 4)
                            {
                                if (num != 8)
                                {
                                    goto IL_D0;
                                }
                            }
                            else
                            {
                                array = BMPImage.bit4to8(array, this.w);
                            }
                        }
                        else
                        {
                            array = BMPImage.bit1to8(array, this.w);
                        }
                    }
                    else
                    {
                        if (num != 16)
                        {
                            if (num != 24)
                            {
                                if (num != 32)
                                {
                                    goto IL_D0;
                                }
                                array = BMPImage.bit32to24(array, this.w);
                            }
                        }
                        else
                        {
                            if (this.r5g6b5)
                            {
                                array = BMPImage.bit16to24(array, this.w);
                            }
                            else
                            {
                                array = BMPImage.bit16to24b(array, this.w);
                            }
                        }
                    }
                    int num2 = this.w * (this.h - i - 1) * 3;
                    if (this.palette != null)
                    {
                        for (int j = 0; j < this.w; j++)
                        {
                            this.image[num2++] = this.palette[(array[j] < 0) ? ((int)array[j] + 256) : ((int)array[j])][2];
                            this.image[num2++] = this.palette[(array[j] < 0) ? ((int)array[j] + 256) : ((int)array[j])][1];
                            this.image[num2++] = this.palette[(array[j] < 0) ? ((int)array[j] + 256) : ((int)array[j])][0];
                        }
                    }
                    else
                    {
                        for (int k = 0; k < this.w * 3; k += 3)
                        {
                            this.image[num2++] = array[k + 2];
                            this.image[num2++] = array[k + 1];
                            this.image[num2++] = array[k];
                        }
                    }
                    i++;
                    continue;
IL_D0:
                    throw new Exception("Can only parse 1 bit, 4bit, 8bit, 16bit, 24bit and 32bit images");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString() + " : BMP parse error: imagedata not correct");
            }
            MemoryStream         memoryStream         = new MemoryStream(32768);
            DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(memoryStream);

            deflaterOutputStream.Write(this.image, 0, this.image.Length);
            deflaterOutputStream.Finish();
            this.deflated = memoryStream.ToArray();
        }
예제 #7
0
        public Image(PDF pdf, System.IO.Stream inputStream, int imageType)
        {
            if (imageType == ImageType.JPEG) {
            JPEGImage jpg = new JPEGImage(inputStream);
            data = jpg.GetData();
            w = jpg.GetWidth();
            h = jpg.GetHeight();
            if ( jpg.GetColorComponents() == 1 ) {
                addImage(pdf, data, imageType, "DeviceGray", 8);
            }
            else if ( jpg.GetColorComponents() == 3 ) {
                addImage(pdf, data, imageType, "DeviceRGB", 8);
            }
            }
            else if (imageType == ImageType.PNG) {
            PNGImage png = new PNGImage(inputStream);
            data = png.GetData();
            w = png.GetWidth();
            h = png.GetHeight();
            if ( png.colorType == 0 ) {
                addImage(pdf, data, imageType, "DeviceGray", png.bitDepth);
            }
            else {
                if ( png.bitDepth == 16 ) {
                    addImage(pdf, data, imageType, "DeviceRGB", 16);
                }
                else {
                    addImage(pdf, data, 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, imageType, "DeviceRGB", 8);
            }

            inputStream.Close();
        }