Exemple #1
0
        /// <param name="size">The size of the image stored in the binary data.</param>
        /// <param name="bits"></param>
        /// <param name="bitsPerChannel"></param>
        /// <param name="position">The position and size at which the image is to
        /// be rendered.</param>
        /// <returns></returns>
        public string AddImage(
            Size size,
            byte[] bits, int bitsPerChannel,
            Rectangle position)
        {
            //	If the image is a JPEG then store it as a single image. If it's
            //	a PNG then separate its RGB channels from its alpha channel and
            //	create one image for each, with the alpha image being the soft
            //	mask of the RGB image.
            string name = null;

            if (Image.IsPng(bits))
            {
                byte[] rgb;
                byte[] alpha;
                Image.SeparateAlphaChannel(bits, out rgb, out alpha);

                //	Store the alpha mask, if there is one
                Image mask = null;
                if (alpha != null)
                {
                    string maskName = "Im" + (_images.Count + 1);
                    mask = new Image(maskName, alpha, bitsPerChannel, size, position, ColorSpace.DeviceGray, Filter.Flate, null);
                    _images.Add(mask);
                }

                //	Store the colour data, with a reference to the mask
                name = "Im" + (_images.Count + 1);
                Image image = new Image(name, rgb, bitsPerChannel, size, position, ColorSpace.DeviceRGB, Filter.Flate, mask);
                _images.Add(image);
            }
            else
            {
                //	Store the full image
                name = "Im" + (_images.Count + 1);
                Image image = new Image(name, bits, bitsPerChannel, size, position, ColorSpace.DeviceRGB, Filter.DCT, null);
                _images.Add(image);
            }

            //	Create a content fragment to show the image on the page. For JPEGs the
            //	fragment refers to the full image, of course, and for PNGs it refers
            //	to the main RGB image.
            ImageFragment frag = new ImageFragment(name, position);

            _content.Add(frag);

            return(name);
        }
Exemple #2
0
        public void AddImage(string name, Rectangle position)
        {
            ImageFragment frag = new ImageFragment(name, position);

            _content.Add(frag);
        }