Exemplo n.º 1
0
        /// <summary>
        /// Constructs a chunk containing an Image.
        /// </summary>
        /// <param name="image">the image</param>
        /// <param name="offsetX">the image offset in the x direction</param>
        /// <param name="offsetY">the image offset in the y direction</param>
        public Chunk(Image image, float offsetX, float offsetY) : this(OBJECT_REPLACEMENT_CHARACTER, new Font())
        {
            Image copyImage = Image.getInstance(image);

            copyImage.setAbsolutePosition(float.NaN, float.NaN);
            setAttribute(IMAGE, new Object[] { copyImage, offsetX, offsetY, false });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an instance of an Image in raw mode.
        /// </summary>
        /// <param name="width">the width of the image in pixels</param>
        /// <param name="height">the height of the image in pixels</param>
        /// <param name="components">1,3 or 4 for GrayScale, RGB and CMYK</param>
        /// <param name="bpc">bits per component</param>
        /// <param name="data">the image data</param>
        /// <param name="transparency">
        /// transparency information in the Mask format of the
        /// image dictionary
        /// </param>
        /// <returns>an object of type ImgRaw</returns>
        public static Image getInstance(int width, int height, int components, int bpc, byte[] data, int[] transparency)
        {
            if (transparency != null && transparency.Length != components * 2)
            {
                throw new BadElementException("Transparency length must be equal to (componentes * 2)");
            }
            if (components == 1 && bpc == 1)
            {
                byte[] g4 = CCITTG4Encoder.compress(data, width, height);
                return(Image.getInstance(width, height, false, Element.CCITTG4, Element.CCITT_BLACKIS1, g4, transparency));
            }
            Image img = new ImgRaw(width, height, components, bpc, data);

            img.transparency = transparency;
            return(img);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns an Image that has been constructed taking in account
        /// the value of some attributes.
        /// </summary>
        /// <param name="attributes">Some attributes</param>
        /// <returns>an Image</returns>
        public static Image getInstance(Properties attributes)
        {
            string value = attributes.Remove(ElementTags.URL);

            if (value == null)
            {
                throw new Exception("The URL of the image is missing.");
            }
            Image image = Image.getInstance(value);
            int   align = Element.ALIGN_LEFT;

            if ((value = attributes.Remove(ElementTags.ALIGN)) != null)
            {
                if (ElementTags.ALIGN_LEFT.ToLower().Equals(value))
                {
                    align |= Image.LEFT;
                }
                else if (ElementTags.ALIGN_RIGHT.ToLower().Equals(value))
                {
                    align |= Image.RIGHT;
                }
                else if (ElementTags.ALIGN_MIDDLE.ToLower().Equals(value))
                {
                    align |= Image.MIDDLE;
                }
            }
            if ((value = attributes.Remove(ElementTags.UNDERLYING)) != null)
            {
                if (bool.Parse(value))
                {
                    align |= Image.UNDERLYING;
                }
            }
            if ((value = attributes.Remove(ElementTags.TEXTWRAP)) != null)
            {
                if (bool.Parse(value))
                {
                    align |= Image.TEXTWRAP;
                }
            }
            image.alignment = align;
            if ((value = attributes.Remove(ElementTags.ALT)) != null)
            {
                image.Alt = value;
            }
            string x;
            string y;

            if (((x = attributes.Remove(ElementTags.ABSOLUTEX)) != null) &&
                ((y = attributes.Remove(ElementTags.ABSOLUTEY)) != null))
            {
                image.setAbsolutePosition(float.Parse(x), float.Parse(y));
            }
            if ((value = attributes.Remove(ElementTags.PLAINWIDTH)) != null)
            {
                image.scaleAbsoluteWidth(float.Parse(value));
            }
            if ((value = attributes.Remove(ElementTags.PLAINHEIGHT)) != null)
            {
                image.scaleAbsoluteHeight(float.Parse(value));
            }
            if ((value = attributes.Remove(ElementTags.ROTATION)) != null)
            {
                image.setRotation(float.Parse(value));
            }
            if (attributes.Count > 0)
            {
                image.MarkupAttributes = attributes;
            }
            return(image);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets an instance of an Image in raw mode.
 /// </summary>
 /// <param name="width">the width of the image in pixels</param>
 /// <param name="height">the height of the image in pixels</param>
 /// <param name="reverseBits"></param>
 /// <param name="typeCCITT"></param>
 /// <param name="parameters"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static Image getInstance(int width, int height, bool reverseBits, int typeCCITT, int parameters, byte[] data)
 {
     return(Image.getInstance(width, height, reverseBits, typeCCITT, parameters, data, null));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Gets an instance of an Image in raw mode.
 /// </summary>
 /// <param name="width">the width of the image in pixels</param>
 /// <param name="height">the height of the image in pixels</param>
 /// <param name="components">1,3 or 4 for GrayScale, RGB and CMYK</param>
 /// <param name="bpc">bits per component</param>
 /// <param name="data">the image data</param>
 /// <returns>an object of type ImgRaw</returns>
 public static Image getInstance(int width, int height, int components, int bpc, byte[] data)
 {
     return(Image.getInstance(width, height, components, bpc, data, null));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets an instance of an Image from a System.Drawing.Image.
 /// </summary>
 /// <param name="image">the System.Drawing.Image to convert</param>
 /// <param name="color">
 /// if different from null the transparency
 /// pixels are replaced by this color
 /// </param>
 /// <returns>an object of type ImgRaw</returns>
 public static Image getInstance(System.Drawing.Image image, Color color)
 {
     return(Image.getInstance(image, color, false));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Gets an instance of an Image from a System.Drwaing.Image.
        /// </summary>
        /// <param name="image">the System.Drawing.Image to convert</param>
        /// <param name="color">
        /// if different from null the transparency
        /// pixels are replaced by this color
        /// </param>
        /// <param name="forceBW">if true the image is treated as black and white</param>
        /// <returns>an object of type ImgRaw</returns>
        public static Image getInstance(System.Drawing.Image image, object color, bool forceBW)
        {
            System.Drawing.Bitmap bm = (System.Drawing.Bitmap)image;
            int w = bm.Width;
            int h = bm.Height;

            if (forceBW)
            {
                int    byteWidth  = (w / 8) + ((w & 7) != 0 ? 1 : 0);
                byte[] pixelsByte = new byte[byteWidth * h];

                int index      = 0;
                int size       = h * w;
                int transColor = 1;
                if (color != null)
                {
                    System.Drawing.Color c = (System.Drawing.Color)color;
                    transColor = (c.R + c.G + c.B < 384) ? 0 : 1;
                }
                int[] transparency = null;
                int   cbyte        = 0x80;
                int   wMarker      = 0;
                int   currByte     = 0;
                if (color != null)
                {
                    for (int j = 0; j < h; j++)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            int alpha = bm.GetPixel(i, j).A;
                            if (alpha < 250)
                            {
                                if (transColor == 1)
                                {
                                    currByte |= cbyte;
                                }
                            }
                            else
                            {
                                if ((bm.GetPixel(i, j).ToArgb() & 0x888) != 0)
                                {
                                    currByte |= cbyte;
                                }
                            }
                            cbyte >>= 1;
                            if (cbyte == 0 || wMarker + 1 >= w)
                            {
                                pixelsByte[index++] = (byte)currByte;
                                cbyte    = 0x80;
                                currByte = 0;
                            }
                            ++wMarker;
                            if (wMarker >= w)
                            {
                                wMarker = 0;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < h; j++)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            if (transparency == null)
                            {
                                int alpha = bm.GetPixel(i, j).A;
                                if (alpha == 0)
                                {
                                    transparency    = new int[2];
                                    transparency[0] = transparency[1] = ((bm.GetPixel(i, j).ToArgb() & 0x888) != 0) ? 1 : 0;
                                }
                            }
                            if ((bm.GetPixel(i, j).ToArgb() & 0x888) != 0)
                            {
                                currByte |= cbyte;
                            }
                            cbyte >>= 1;
                            if (cbyte == 0 || wMarker + 1 >= w)
                            {
                                pixelsByte[index++] = (byte)currByte;
                                cbyte    = 0x80;
                                currByte = 0;
                            }
                            ++wMarker;
                            if (wMarker >= w)
                            {
                                wMarker = 0;
                            }
                        }
                    }
                }
                return(Image.getInstance(w, h, 1, 1, pixelsByte, transparency));
            }
            else
            {
                byte[] pixelsByte = new byte[w * h * 3];

                int index = 0;
                int size  = h * w;
                int red   = 255;
                int green = 255;
                int blue  = 255;
                if (color != null)
                {
                    red   = ((System.Drawing.Color)color).R;
                    green = ((System.Drawing.Color)color).G;
                    blue  = ((System.Drawing.Color)color).B;
                }
                int[] transparency = null;
                if (color != null)
                {
                    for (int j = 0; j < h; j++)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            int alpha = (bm.GetPixel(i, j).ToArgb() >> 24) & 0xff;
                            if (alpha < 250)
                            {
                                pixelsByte[index++] = (byte)red;
                                pixelsByte[index++] = (byte)green;
                                pixelsByte[index++] = (byte)blue;
                            }
                            else
                            {
                                pixelsByte[index++] = (byte)((bm.GetPixel(i, j).ToArgb() >> 16) & 0xff);
                                pixelsByte[index++] = (byte)((bm.GetPixel(i, j).ToArgb() >> 8) & 0xff);
                                pixelsByte[index++] = (byte)((bm.GetPixel(i, j).ToArgb()) & 0xff);
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < h; j++)
                    {
                        for (int i = 0; i < w; i++)
                        {
                            if (transparency == null)
                            {
                                int alpha = (bm.GetPixel(i, j).ToArgb() >> 24) & 0xff;
                                if (alpha == 0)
                                {
                                    transparency    = new int[6];
                                    transparency[0] = transparency[1] = (bm.GetPixel(i, j).ToArgb() >> 16) & 0xff;
                                    transparency[2] = transparency[3] = (bm.GetPixel(i, j).ToArgb() >> 8) & 0xff;
                                    transparency[4] = transparency[5] = bm.GetPixel(i, j).ToArgb() & 0xff;
                                }
                            }
                            pixelsByte[index++] = (byte)((bm.GetPixel(i, j).ToArgb() >> 16) & 0xff);
                            pixelsByte[index++] = (byte)((bm.GetPixel(i, j).ToArgb() >> 8) & 0xff);
                            pixelsByte[index++] = (byte)((bm.GetPixel(i, j)).ToArgb() & 0xff);
                        }
                    }
                }
                return(Image.getInstance(w, h, 3, 8, pixelsByte, transparency));
            }
        }