OfficeOpenXml.ExcelHeaderFooterText.InsertPicture C# (CSharp) Method

InsertPicture() public method

Inserts a picture at the end of the text in the header or footer
public InsertPicture ( FileInfo PictureFile, PictureAlignment Alignment ) : OfficeOpenXml.Drawing.Vml.ExcelVmlDrawingPicture
PictureFile System.IO.FileInfo The image object containing the Picture
Alignment PictureAlignment Alignment. The image object will be inserted at the end of the Text.
return OfficeOpenXml.Drawing.Vml.ExcelVmlDrawingPicture
        public ExcelVmlDrawingPicture InsertPicture(FileInfo PictureFile, PictureAlignment Alignment)
        {
            string id = ValidateImage(Alignment);

            Image Picture;
            try
            {
                if (!PictureFile.Exists)
                {
                    throw (new FileNotFoundException(string.Format("{0} is missing", PictureFile.FullName)));
                }
                Picture = Image.FromFile(PictureFile.FullName);
            }
            catch (Exception ex)
            {
                throw (new InvalidDataException("File is not a supported image-file or is corrupt", ex));
            }

            ImageConverter ic = new ImageConverter();
            string contentType = ExcelPicture.GetContentType(PictureFile.Extension);
            var uriPic = XmlHelper.GetNewUri(_ws._package.Package, "/xl/media/"+PictureFile.Name.Substring(0, PictureFile.Name.Length-PictureFile.Extension.Length) + "{0}" + PictureFile.Extension);
            byte[] imgBytes = (byte[])ic.ConvertTo(Picture, typeof(byte[]));
            var ii = _ws.Workbook._package.AddImage(imgBytes, uriPic, contentType);

            return AddImage(Picture, id, ii);
        }

Same methods

ExcelHeaderFooterText::InsertPicture ( Image Picture, PictureAlignment Alignment ) : OfficeOpenXml.Drawing.Vml.ExcelVmlDrawingPicture