@@ -676,6 +676,23 @@ public void CreateMultiFrameTiffStream_Empty_Sequence_Throws()
676676 act . Should ( ) . Throw < ArgumentException > ( ) ;
677677 }
678678
679+ [ FactWithAutomaticDisplayName ]
680+ public void CreateMultiFrameTiffBytes_PreservesResolution_FromPixelsPerMeterSource ( )
681+ {
682+ const double dpi = 300d ;
683+ double pixelsPerMetre = dpi / 0.0254d ; // 300 DPI expressed in pixels per metre
684+
685+ using var page = MakeBitmapWithResolution ( 220 , 300 , new Rgb24 ( 40 , 90 , 160 ) ,
686+ pixelsPerMetre , PixelResolutionUnit . PixelsPerMeter ) ;
687+
688+ byte [ ] tiff = AnyBitmap . CreateMultiFrameTiffBytes ( new [ ] { page } ) ;
689+ var pages = ReadTiffDirectories ( tiff ) ;
690+
691+ pages . Should ( ) . ContainSingle ( ) ;
692+ ToDotsPerInch ( pages [ 0 ] . XResolution , pages [ 0 ] . ResolutionUnit )
693+ . Should ( ) . BeApproximately ( dpi , 2d ) ;
694+ }
695+
679696 [ FactWithAutomaticDisplayName ]
680697 public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels ( )
681698 {
@@ -708,11 +725,17 @@ public void CreateMultiFrameTiff_Preserves_Rgb24_Pixels()
708725 }
709726
710727 private static AnyBitmap CreateSolidBitmap ( int width , int height , Rgb24 color , int dpi )
728+ {
729+ return MakeBitmapWithResolution ( width , height , color , dpi , PixelResolutionUnit . PixelsPerInch ) ;
730+ }
731+
732+ private static AnyBitmap MakeBitmapWithResolution ( int width , int height , Rgb24 color ,
733+ double resolution , PixelResolutionUnit unit )
711734 {
712735 var image = new SixLabors . ImageSharp . Image < Rgb24 > ( width , height , color ) ;
713- image . Metadata . HorizontalResolution = dpi ;
714- image . Metadata . VerticalResolution = dpi ;
715- image . Metadata . ResolutionUnits = PixelResolutionUnit . PixelsPerInch ;
736+ image . Metadata . HorizontalResolution = resolution ;
737+ image . Metadata . VerticalResolution = resolution ;
738+ image . Metadata . ResolutionUnits = unit ;
716739 return image ;
717740 }
718741
0 commit comments