ImageCompositionTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.IO;
  2. using System.Runtime.CompilerServices;
  3. using System.Threading.Tasks;
  4. using Avalonia.Controls;
  5. using Avalonia.Media;
  6. using Avalonia.Media.Imaging;
  7. using Xunit;
  8. namespace Avalonia.Skia.RenderTests
  9. {
  10. public class ImageCompositionTests : TestBase
  11. {
  12. private readonly Bitmap _bitmapA;
  13. private readonly Bitmap _bitmapB;
  14. public ImageCompositionTests()
  15. : base(@"Controls\Image\composition")
  16. {
  17. _bitmapA = new Bitmap(Path.Combine(OutputPath, "A.png"));
  18. _bitmapB = new Bitmap(Path.Combine(OutputPath, "B.png"));
  19. }
  20. [Fact]
  21. public async Task Image_Blend_SourceOver() => await TestCompositeMode(BitmapBlendingMode.SourceOver);
  22. [Fact]
  23. public async Task Image_Blend_Source() => await TestCompositeMode(BitmapBlendingMode.Source);
  24. [Fact]
  25. public async Task Image_Blend_SourceIn() => await TestCompositeMode(BitmapBlendingMode.SourceIn);
  26. [Fact]
  27. public async Task Image_Blend_SourceOut() => await TestCompositeMode(BitmapBlendingMode.SourceOut);
  28. [Fact]
  29. public async Task Image_Blend_SourceAtop() => await TestCompositeMode(BitmapBlendingMode.SourceAtop);
  30. [Fact]
  31. public async Task Image_Blend_Destination() => await TestCompositeMode(BitmapBlendingMode.Destination);
  32. [Fact]
  33. public async Task Image_Blend_DestinationIn() => await TestCompositeMode(BitmapBlendingMode.DestinationIn);
  34. [Fact]
  35. public async Task Image_Blend_DestinationOut() => await TestCompositeMode(BitmapBlendingMode.DestinationOut);
  36. [Fact]
  37. public async Task Image_Blend_DestinationOver() => await TestCompositeMode(BitmapBlendingMode.DestinationOver);
  38. [Fact]
  39. public async Task Image_Blend_DestinationAtop() => await TestCompositeMode(BitmapBlendingMode.DestinationAtop);
  40. [Fact]
  41. public async Task Image_Blend_Xor() => await TestCompositeMode(BitmapBlendingMode.Xor);
  42. private async Task TestCompositeMode(BitmapBlendingMode blendMode, [CallerMemberName] string testName = "")
  43. {
  44. var panel = new Panel();
  45. panel.Children.Add(new Image() { Source = _bitmapA });
  46. panel.Children.Add(new Image() { Source = _bitmapB, BlendMode = blendMode });
  47. var target = new Decorator
  48. {
  49. Width = 512,
  50. Height = 512,
  51. Child = new Border
  52. {
  53. Background = Brushes.Transparent,
  54. Child = panel
  55. }
  56. };
  57. await RenderToFile(target,testName);
  58. CompareImages(testName);
  59. }
  60. }
  61. }