ImageTests.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) The Perspex 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 Perspex.Controls;
  5. using Perspex.Media;
  6. using Perspex.Media.Imaging;
  7. using Xunit;
  8. #if PERSPEX_CAIRO
  9. namespace Perspex.Cairo.RenderTests.Controls
  10. #elif PERSPEX_SKIA
  11. namespace Perspex.Skia.RenderTests
  12. #else
  13. namespace Perspex.Direct2D1.RenderTests.Controls
  14. #endif
  15. {
  16. public class ImageTests : TestBase
  17. {
  18. private readonly Bitmap _bitmap;
  19. public ImageTests()
  20. : base(@"Controls\Image")
  21. {
  22. _bitmap = new Bitmap(Path.Combine(OutputPath, "test.png"));
  23. }
  24. [Fact]
  25. public void Image_Stretch_None()
  26. {
  27. Decorator target = new Decorator
  28. {
  29. Padding = new Thickness(20, 8),
  30. Width = 200,
  31. Height = 200,
  32. Child = new Border
  33. {
  34. Background = Brushes.Red,
  35. Child = new Image
  36. {
  37. Source = _bitmap,
  38. Stretch = Stretch.None,
  39. }
  40. }
  41. };
  42. RenderToFile(target);
  43. CompareImages();
  44. }
  45. [Fact]
  46. public void Image_Stretch_Fill()
  47. {
  48. Decorator target = new Decorator
  49. {
  50. Padding = new Thickness(20, 8),
  51. Width = 200,
  52. Height = 200,
  53. Child = new Border
  54. {
  55. Background = Brushes.Red,
  56. Child = new Image
  57. {
  58. Source = _bitmap,
  59. Stretch = Stretch.Fill,
  60. }
  61. }
  62. };
  63. RenderToFile(target);
  64. CompareImages();
  65. }
  66. [Fact]
  67. public void Image_Stretch_Uniform()
  68. {
  69. Decorator target = new Decorator
  70. {
  71. Padding = new Thickness(20, 8),
  72. Width = 200,
  73. Height = 200,
  74. Child = new Border
  75. {
  76. Background = Brushes.Red,
  77. Child = new Image
  78. {
  79. Source = _bitmap,
  80. Stretch = Stretch.Uniform,
  81. }
  82. }
  83. };
  84. RenderToFile(target);
  85. CompareImages();
  86. }
  87. [Fact]
  88. public void Image_Stretch_UniformToFill()
  89. {
  90. Decorator target = new Decorator
  91. {
  92. Padding = new Thickness(20, 8),
  93. Width = 200,
  94. Height = 200,
  95. Child = new Border
  96. {
  97. Background = Brushes.Red,
  98. Child = new Image
  99. {
  100. Source = _bitmap,
  101. Stretch = Stretch.UniformToFill,
  102. }
  103. }
  104. };
  105. RenderToFile(target);
  106. CompareImages();
  107. }
  108. }
  109. }