Example #1
0
        public void AddImage(byte[] imgBuf, float height, float width, RPLFormat.Sizings sizing)
        {
            if (imgBuf == null || imgBuf.Length == 0)
            {
                sizing = RPLFormat.Sizings.Clip;
                imgBuf = PictureDescriptor.INVALIDIMAGEDATA;
            }
            OfficeImageHasher officeImageHasher = new OfficeImageHasher(imgBuf);

            byte[]    hash = officeImageHasher.Hash;
            int       num  = Word97Writer.ToTwips(height);
            int       num2 = Word97Writer.ToTwips(width);
            int       num3 = (int)this.m_dataStream.Position;
            ImageHash key  = new ImageHash(hash, sizing, num2, num);

            if (this.m_images.ContainsKey(key))
            {
                num3 = this.m_images[key];
            }
            else
            {
                PictureDescriptor pictureDescriptor = new PictureDescriptor(imgBuf, hash, num2, num, sizing, this.m_imgIndex);
                pictureDescriptor.Serialize(this.m_dataStream);
                this.m_imgIndex++;
                this.m_images.Add(key, num3);
            }
            this.m_charFormat.SetIsInlineImage(num3);
            this.WriteSpecialText("\u0001");
        }
Example #2
0
        public void AddImage(string imageName, Stream imageData, ImageFormat format, int rowStart, double rowStartPercentage, int columnStart, double columnStartPercentage, int rowEnd, double rowEndPercentage, int columnEnd, double colEndPercentage, string hyperlinkURL, bool isBookmarkLink)
        {
            if (imageData.CanSeek)
            {
                imageData.Seek(0L, SeekOrigin.Begin);
            }
            if (rowStart < 0)
            {
                rowStart = 0;
            }
            if (columnStart < 0)
            {
                columnStart = 0;
            }
            if (rowEnd < 0)
            {
                rowEnd = 0;
            }
            if (columnEnd < 0)
            {
                columnEnd = 0;
            }
            this.LimitPercentage(ref rowStartPercentage);
            this.LimitPercentage(ref columnStartPercentage);
            this.LimitPercentage(ref rowEndPercentage);
            this.LimitPercentage(ref colEndPercentage);
            Anchor            startPosition     = this._currentSheet.CreateAnchor(rowStart, columnStart, columnStartPercentage, rowStartPercentage);
            Anchor            endPosition       = this._currentSheet.CreateAnchor(rowEnd, columnEnd, colEndPercentage, rowEndPercentage);
            string            extension         = (!(format.Guid == ImageFormat.Bmp.Guid)) ? ((!(format.Guid == ImageFormat.Gif.Guid)) ? ((!(format.Guid == ImageFormat.Jpeg.Guid)) ? "png" : "jpg") : "gif") : "bmp";
            OfficeImageHasher officeImageHasher = new OfficeImageHasher(imageData);
            string            uniqueId          = Convert.ToBase64String(officeImageHasher.Hash);

            imageData.Seek(0L, SeekOrigin.Begin);
            Picture picture = this._currentSheet.Pictures.CreatePicture(uniqueId, extension, imageData, startPosition, endPosition);

            this._picturesStartingOnCurrentRow.Add(picture);
            this.AddPictureToUpdateCollection(ref this._picturesToUpdateByEndRow, rowEnd, picture);
            this.AddPictureToUpdateCollection(ref this._picturesToUpdateByStartColumn, columnStart, picture);
            this.AddPictureToUpdateCollection(ref this._picturesToUpdateByEndColumn, columnEnd, picture);
            if (!string.IsNullOrEmpty(hyperlinkURL))
            {
                if (isBookmarkLink)
                {
                    BookmarkTargetInfo bookmark = default(BookmarkTargetInfo);
                    if (this._bookmarkTargets.TryGetValue(hyperlinkURL, out bookmark))
                    {
                        picture.Hyperlink = this.GetPictureBookmarkLink(bookmark);
                    }
                    else
                    {
                        this._unresolvedPictureBookmarks.Add(new PictureLinkInfo(picture, hyperlinkURL));
                    }
                }
                else
                {
                    picture.Hyperlink = hyperlinkURL;
                }
            }
        }