예제 #1
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="image">The image to draw.</param>
        public void DrawImage(PortableDocumentImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            var imageId = GetCached(image, this.imageCache, () => this.AddImage(image));

            this.AppendLine("{0} Do", imageId);
        }
예제 #2
0
        /// <summary>
        /// Adds an image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <returns>The added object.</returns>
        private string AddImage(PortableDocumentImage image)
        {
            int i           = this.xobjects.Count + 1;
            var imageObject = this.AddObject(PdfWriter.ObjectType.XObject);

            imageObject["/Subtype"]          = "/Image";
            imageObject["/Width"]            = image.Width;
            imageObject["/Height"]           = image.Height;
            imageObject["/ColorSpace"]       = "/" + image.ColorSpace;
            imageObject["/Interpolate"]      = image.Interpolate;
            imageObject["/BitsPerComponent"] = image.BitsPerComponent;

            ////var flateData = Flate(bits);
            ////var encodedData = Ascii85Encode(flateData);
            ////image["/Length"] = encodedData.Length;
            ////image["/Filter"] = new[] { "/ASCII85Decode", "/FlateDecode" };

            var encodedData = Ascii85Encode(image.Bits);

            imageObject["/Length"] = encodedData.Length;
            imageObject["/Filter"] = "/ASCII85Decode";

            imageObject.Append(encodedData);
            string imageId = "/Image" + i;

            this.xobjects.Add(imageId, imageObject);

            if (image.MaskBits != null)
            {
                var maskImage = this.AddObject(PdfWriter.ObjectType.XObject);
                maskImage["/Subtype"]          = "/Image";
                maskImage["/Width"]            = image.Width;
                maskImage["/Height"]           = image.Height;
                maskImage["/ColorSpace"]       = "/DeviceGray";
                maskImage["/Interpolate"]      = image.Interpolate;
                maskImage["/BitsPerComponent"] = image.BitsPerComponent;
                var encodedMaskData = Ascii85Encode(image.MaskBits);
                maskImage["/Length"] = encodedMaskData.Length;
                maskImage["/Filter"] = "/ASCII85Decode";
                maskImage.Append(encodedMaskData);
                imageObject["/SMask"] = maskImage;
            }

            return(imageId);
        }