Skip to content

Commit e086d50

Browse files
committed
Fixes issue #1982.
1 parent 5f37968 commit e086d50

8 files changed

Lines changed: 307 additions & 247 deletions

File tree

src/EPPlus/Drawing/ExcelPicture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Date Author Change
2222
using System.Globalization;
2323
using OfficeOpenXml.FormulaParsing.Excel.Functions.MathFunctions;
2424
using System.ComponentModel;
25+
using System.Xml.Linq;
26+
2527

2628
#if NETFULL
2729
using System.Drawing.Imaging;
@@ -93,6 +95,16 @@ internal ExcelPicture(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shap
9395
Image.Type = type.Value;
9496
byte[] iby = ms.ToArray();
9597
Image.ImageBytes = iby;
98+
using (var picMs = new MemoryStream(iby))
99+
{
100+
if (drawings._package.Settings.ImageSettings.GetImageBounds(picMs, type.Value, out double width, out double height, out double horizontalResolution, out double verticalResolution))
101+
{
102+
Image.Bounds.Width = width;
103+
Image.Bounds.Height = height;
104+
Image.Bounds.HorizontalResolution = horizontalResolution;
105+
Image.Bounds.VerticalResolution = verticalResolution;
106+
}
107+
}
96108
var ii = _drawings._package.PictureStore.LoadImage(iby, container.UriPic, Part);
97109
var pd = (IPictureRelationDocument)_drawings;
98110
if (pd.Hashes.ContainsKey(ii.Hash))

src/EPPlus/Drawing/ImageHandling/GenericImageHandler.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public HashSet<ePictureType> SupportedTypes
2626
public Exception LastException { get; private set; } = null;
2727

2828
/// <summary>
29-
/// Retreives the image bounds and resolution for an image
29+
/// Retrieves the image bounds and resolution for an image
3030
/// </summary>
3131
/// <param name="image">The image data</param>
3232
/// <param name="type">Type type of image</param>
@@ -42,7 +42,16 @@ public bool GetImageBounds(MemoryStream image, ePictureType type, out double wid
4242
{
4343
width = 0;
4444
height = 0;
45-
return ImageReader.TryGetImageBounds(type, image, ref width, ref height, out horizontalResolution, out verticalResolution);
45+
var ret = ImageReader.TryGetImageBounds(type, image, ref width, ref height, out horizontalResolution, out verticalResolution);
46+
if (ret == false)
47+
{
48+
var t = ImageReader.GetPictureType(image, false);
49+
if (t.HasValue)
50+
{
51+
return ImageReader.TryGetImageBounds(t.Value, image, ref width, ref height, out horizontalResolution, out verticalResolution);
52+
}
53+
}
54+
return ret;
4655
}
4756
catch (Exception ex)
4857
{
@@ -56,7 +65,7 @@ public bool GetImageBounds(MemoryStream image, ePictureType type, out double wid
5665
}
5766

5867
/// <summary>
59-
/// Returns if the handler is valid for the enviornment.
68+
/// Returns if the handler is valid for the environment.
6069
/// The generic image handler is valid in all environments, so it will always return true.
6170
/// </summary>
6271
/// <returns></returns>

0 commit comments

Comments
 (0)