ImageTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using Avalonia.Controls;
  6. using Avalonia.Media;
  7. using Avalonia.Media.Imaging;
  8. using Xunit;
  9. #if AVALONIA_SKIA
  10. namespace Avalonia.Skia.RenderTests
  11. #else
  12. namespace Avalonia.Direct2D1.RenderTests.Controls
  13. #endif
  14. {
  15. public class ImageTests : TestBase
  16. {
  17. private readonly Bitmap _bitmap;
  18. public ImageTests()
  19. : base(@"Controls\Image")
  20. {
  21. _bitmap = new Bitmap(Path.Combine(OutputPath, "test.png"));
  22. }
  23. [Fact]
  24. public async Task Image_Stretch_None()
  25. {
  26. Decorator target = new Decorator
  27. {
  28. Padding = new Thickness(20, 8),
  29. Width = 200,
  30. Height = 200,
  31. Child = new Border
  32. {
  33. Background = Brushes.Red,
  34. Child = new Image
  35. {
  36. Source = _bitmap,
  37. Stretch = Stretch.None,
  38. }
  39. }
  40. };
  41. await RenderToFile(target);
  42. CompareImages();
  43. }
  44. [Fact]
  45. public async Task Image_Stretch_Fill()
  46. {
  47. Decorator target = new Decorator
  48. {
  49. Padding = new Thickness(20, 8),
  50. Width = 200,
  51. Height = 200,
  52. Child = new Border
  53. {
  54. Background = Brushes.Red,
  55. Child = new Image
  56. {
  57. Source = _bitmap,
  58. Stretch = Stretch.Fill,
  59. }
  60. }
  61. };
  62. await RenderToFile(target);
  63. CompareImages();
  64. }
  65. [Fact]
  66. public async Task Image_Stretch_Uniform()
  67. {
  68. Decorator target = new Decorator
  69. {
  70. Padding = new Thickness(20, 8),
  71. Width = 200,
  72. Height = 200,
  73. Child = new Border
  74. {
  75. Background = Brushes.Red,
  76. Child = new Image
  77. {
  78. Source = _bitmap,
  79. Stretch = Stretch.Uniform,
  80. }
  81. }
  82. };
  83. await RenderToFile(target);
  84. CompareImages();
  85. }
  86. [Fact]
  87. public async Task Image_Stretch_UniformToFill()
  88. {
  89. Decorator target = new Decorator
  90. {
  91. Padding = new Thickness(20, 8),
  92. Width = 200,
  93. Height = 200,
  94. Child = new Border
  95. {
  96. Background = Brushes.Red,
  97. Child = new Image
  98. {
  99. Source = _bitmap,
  100. Stretch = Stretch.UniformToFill,
  101. }
  102. }
  103. };
  104. await RenderToFile(target);
  105. CompareImages();
  106. }
  107. }
  108. }