1- // Copyright (c) Six Labors and contributors.
1+ // Copyright (c) Six Labors and contributors.
22// Licensed under the Apache License, Version 2.0.
33
44using System ;
@@ -16,6 +16,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing
1616{
1717 using SixLabors . ImageSharp . Advanced ;
1818 using SixLabors . ImageSharp . Tests . TestUtilities . ImageComparison ;
19+ using SixLabors . Primitives ;
20+ using SixLabors . Shapes ;
1921
2022 [ GroupOutput ( "Drawing/GradientBrushes" ) ]
2123 public class FillLinearGradientBrushTests
@@ -392,5 +394,43 @@ public void MultiplePointGradients<TPixel>(
392394 false ,
393395 false ) ;
394396 }
397+
398+ [ Theory ]
399+ [ WithBlankImages ( 200 , 200 , PixelTypes . Rgba32 ) ]
400+ public void GradientsWithTransparencyOnExistingBackground < TPixel > ( TestImageProvider < TPixel > provider )
401+ where TPixel : struct , IPixel < TPixel >
402+ {
403+ provider . VerifyOperation (
404+ image =>
405+ {
406+ image . Mutate ( i => i . Fill ( Color . Red ) ) ;
407+ image . Mutate ( ApplyGloss ) ;
408+
409+ } ) ;
410+
411+ void ApplyGloss ( IImageProcessingContext ctx )
412+ {
413+ Size size = ctx . GetCurrentSize ( ) ;
414+ IPathCollection glossPath = BuildGloss ( size . Width , size . Height ) ;
415+ var graphicsOptions = new GraphicsOptions ( true )
416+ {
417+ ColorBlendingMode = PixelColorBlendingMode . Normal ,
418+ AlphaCompositionMode = PixelAlphaCompositionMode . SrcAtop
419+ } ;
420+ var linearGradientBrush = new LinearGradientBrush ( new Point ( 0 , 0 ) , new Point ( 0 , size . Height / 2 ) , GradientRepetitionMode . Repeat , new ColorStop ( 0 , Color . White . WithAlpha ( 0.5f ) ) , new ColorStop ( 1 , Color . White . WithAlpha ( 0.25f ) ) ) ;
421+ ctx . Fill ( graphicsOptions , linearGradientBrush , glossPath ) ;
422+ }
423+
424+ IPathCollection BuildGloss ( int imageWidth , int imageHeight )
425+ {
426+ var pathBuilder = new PathBuilder ( ) ;
427+ pathBuilder . AddLine ( new PointF ( 0 , 0 ) , new PointF ( imageWidth , 0 ) ) ;
428+ pathBuilder . AddLine ( new PointF ( imageWidth , 0 ) , new PointF ( imageWidth , imageHeight * 0.4f ) ) ;
429+ pathBuilder . AddBezier ( new PointF ( imageWidth , imageHeight * 0.4f ) , new PointF ( imageWidth / 2 , imageHeight * 0.6f ) , new PointF ( 0 , imageHeight * 0.4f ) ) ;
430+ pathBuilder . CloseFigure ( ) ;
431+ return new PathCollection ( pathBuilder . Build ( ) ) ;
432+ }
433+ }
434+
395435 }
396- }
436+ }
0 commit comments