瀏覽代碼

Merge pull request #100 from malickf/master

fix AddImage bug  : recursive loop
master
PrzemyslawKlys 9 年之前
父節點
當前提交
95530ee77b
共有 2 個文件被更改,包括 15 次插入17 次删除
  1. 14
    16
      DocX/DocX.cs
  2. 1
    1
      UnitTests/DocXUnitTests.cs

+ 14
- 16
DocX/DocX.cs 查看文件

@@ -2932,27 +2932,25 @@ namespace Novacode
/// </example>
/// <seealso cref="AddImage(Stream, string)"/>
/// <seealso cref="Paragraph.InsertPicture"/>
public Image AddImage(string filename, string contentType = "image/jpeg")
public Image AddImage(string filename)
{
if (string.IsNullOrEmpty(contentType))
string contentType = "";
// The extension this file has will be taken to be its format.
switch (Path.GetExtension(filename))
{
// The extension this file has will be taken to be its format.
switch (Path.GetExtension(filename))
{
case ".tiff": contentType = "image/tif"; break;
case ".tif": contentType = "image/tif"; break;
case ".png": contentType = "image/png"; break;
case ".bmp": contentType = "image/png"; break;
case ".gif": contentType = "image/gif"; break;
case ".jpg": contentType = "image/jpg"; break;
case ".jpeg": contentType = "image/jpeg"; break;
default: contentType = "image/jpg"; break;
}
case ".tiff": contentType = "image/tif"; break;
case ".tif": contentType = "image/tif"; break;
case ".png": contentType = "image/png"; break;
case ".bmp": contentType = "image/png"; break;
case ".gif": contentType = "image/gif"; break;
case ".jpg": contentType = "image/jpg"; break;
case ".jpeg": contentType = "image/jpeg"; break;
default: contentType = "image/jpg"; break;
}
return AddImage(filename, contentType);
return AddImage(filename as object, contentType);
}
/// <summary>
/// Add an Image into this document from a Stream.
/// </summary>

+ 1
- 1
UnitTests/DocXUnitTests.cs 查看文件

@@ -91,7 +91,7 @@ namespace UnitTests
// Check file size
FileInfo f = new FileInfo( temporaryFilePath );
Assert.IsTrue( f.Length == 9659 );
Assert.IsTrue( f.Length == 9658 );
}
// Delete the tempory file.

Loading…
取消
儲存