3
3
using Microsoft . CSharp . RuntimeBinder ;
4
4
using SixLabors . ImageSharp ;
5
5
using SixLabors . ImageSharp . Advanced ;
6
+ using SixLabors . ImageSharp . Formats ;
7
+ using SixLabors . ImageSharp . Metadata ;
6
8
using SixLabors . ImageSharp . PixelFormats ;
7
9
using SixLabors . ImageSharp . Processing ;
8
10
using System ;
@@ -21,6 +23,10 @@ public class SharpImage : ImageBase<IImage>
21
23
{
22
24
Image Image => UnderlyingImage as Image ?? throw new NotSupportedException ( ) ;
23
25
26
+ ImageMetadata Metadata => UnderlyingImage . Metadata ;
27
+
28
+ PixelTypeInfo PixelType => UnderlyingImage . PixelType ;
29
+
24
30
public SharpImage ( IImage underlyingImage , IFileFormat < IImage > format ) : base ( underlyingImage , format )
25
31
{
26
32
@@ -30,13 +36,31 @@ public SharpImage(IImage underlyingImage, IFileFormat<IImage> format) : base(und
30
36
31
37
public override int Height => UnderlyingImage . Height ;
32
38
33
- public override double HorizontalResolution => UnderlyingImage . Metadata . HorizontalResolution ;
39
+ public override double HorizontalResolution => ResolutionUnit * Metadata . HorizontalResolution ;
34
40
35
- public override double VerticalResolution => UnderlyingImage . Metadata . VerticalResolution ;
41
+ public override double VerticalResolution => ResolutionUnit * Metadata . VerticalResolution ;
42
+
43
+ private double ResolutionUnit {
44
+ get {
45
+ switch ( Metadata . ResolutionUnits )
46
+ {
47
+ case PixelResolutionUnit . AspectRatio :
48
+ return 0 ;
49
+ case PixelResolutionUnit . PixelsPerInch :
50
+ return 1 ;
51
+ case PixelResolutionUnit . PixelsPerCentimeter :
52
+ return 2.54d ;
53
+ case PixelResolutionUnit . PixelsPerMeter :
54
+ return 0.0254d ;
55
+ default :
56
+ throw new NotSupportedException ( ) ;
57
+ }
58
+ }
59
+ }
36
60
37
- public override bool HasAlpha => UnderlyingImage . PixelType . AlphaRepresentation is not ( 0 or null ) ;
61
+ public override bool HasAlpha => PixelType . AlphaRepresentation is not ( 0 or null ) ;
38
62
39
- public override int BitDepth => UnderlyingImage . PixelType . BitsPerPixel ;
63
+ public override int BitDepth => PixelType . BitsPerPixel ;
40
64
41
65
public override IReadOnlyList < Color > Palette => Array . Empty < Color > ( ) ; // TODO
42
66
0 commit comments