Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions main/SS/Util/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace NPOI.SS.Util
using NPOI.SS.UserModel;
using NPOI.Util;
using SixLabors.ImageSharp;

using SixLabors.ImageSharp.Metadata;

/**
* @author Yegor Kozlov
*/
Expand Down Expand Up @@ -103,7 +104,28 @@ public static Size GetImageDimension(Stream is1, PictureType type)
*/
public static int[] GetResolution(Image r)
{
return new int[] { (int)r.Metadata.HorizontalResolution, (int)r.Metadata.VerticalResolution };
ImageMetadata imageMetadata = r.Metadata;

double horizontalResolution = 0;
double verticalResolution = 0;

if (imageMetadata.ResolutionUnits == PixelResolutionUnit.PixelsPerMeter)
{
horizontalResolution = imageMetadata.HorizontalResolution * 0.0254D;
verticalResolution = imageMetadata.VerticalResolution * 0.0254D;
}
else if (imageMetadata.ResolutionUnits == PixelResolutionUnit.PixelsPerCentimeter)
{
horizontalResolution = imageMetadata.HorizontalResolution * 2.54D;
verticalResolution = imageMetadata.VerticalResolution * 2.54D;
}
else
{
horizontalResolution = imageMetadata.HorizontalResolution;
verticalResolution = imageMetadata.VerticalResolution;
}

return new int[] { (int)Math.Round(horizontalResolution), (int)Math.Round(verticalResolution) };
}

/**
Expand Down Expand Up @@ -296,4 +318,4 @@ private static double GetRowHeightInPixels(ISheet sheet, int rowNum)
}
}

}
}