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);
}