@@ -17,16 +17,18 @@ namespace Shouldly;
17
17
[ EditorBrowsable ( EditorBrowsableState . Never ) ]
18
18
public static partial class ShouldMatchApprovedExtensions
19
19
{
20
- public static void ShouldMatchApprovedImage ( this byte [ ] imageBytes , string ? discriminator = null , string ? customMessage = null )
20
+ public static void ShouldMatchApprovedImage ( this byte [ ] imageBytes , string ? discriminator = null , string ? customMessage = null , bool asMonochrome = false )
21
21
{
22
22
using var ms = new MemoryStream ( imageBytes ) ;
23
23
using var image = ( Bitmap ) Image . FromStream ( ms ) ;
24
- image . ShouldMatchApproved ( discriminator , customMessage ) ;
24
+ image . ShouldMatchApproved ( discriminator , customMessage , asMonochrome ) ;
25
25
}
26
- public static void ShouldMatchApproved ( this Bitmap image , string ? discriminator = null , string ? customMessage = null )
26
+ public static void ShouldMatchApproved ( this Bitmap image , string ? discriminator = null , string ? customMessage = null , bool asMonochrome = false )
27
27
{
28
28
// encode to gif first for easier visual verification, and using a third party lib to avoid platform-specific compression differences
29
29
var readableBitmapData = image . GetReadableBitmapData ( ) ;
30
+ if ( asMonochrome )
31
+ readableBitmapData = readableBitmapData . Clone ( KnownPixelFormat . Format1bppIndexed ) ;
30
32
var ms = new MemoryStream ( ) ;
31
33
GifEncoder . EncodeImage ( readableBitmapData , ms ) ;
32
34
ms . ToArray ( ) . ShouldMatchApproved ( "gif" , discriminator , customMessage ) ;
0 commit comments