diff --git a/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj b/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj index 206ed3229951..cea07ff91028 100644 --- a/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj +++ b/src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue30006.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue30006.cs new file mode 100644 index 000000000000..179e25dea3c0 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue30006.cs @@ -0,0 +1,77 @@ +using System.Reflection; +using Microsoft.Maui.Graphics.Platform; +using IImage = Microsoft.Maui.Graphics.IImage; + +namespace Controls.TestCases.HostApp.Issues; + +[Issue(IssueTracker.Github, 30006, "The downsized image continues to retain its original dimensions", PlatformAffected.iOS)] +public class Issue30006 : ContentPage +{ + Label _convertedImageStatusLabel; + public Issue30006() + { + _convertedImageStatusLabel = new Label + { + AutomationId = "ConvertedImage", + Text = "Result Image Status: " + }; + + VerticalStackLayout verticalStackLayout = new VerticalStackLayout + { + Padding = new Thickness(20), + Spacing = 10, + Children = + { + CreateButton("DownSize", OnDownSize), + _convertedImageStatusLabel, + } + }; + + Content = new ScrollView { Content = verticalStackLayout }; + } + + Button CreateButton(string text, EventHandler handler) + { + Button button = new Button + { + AutomationId = $"Issue30006DownSizeBtn", + Text = text, + HorizontalOptions = LayoutOptions.Fill + }; + + button.Clicked += handler; + return button; + } + + async Task LoadImageAsync() + { + var assembly = GetType().GetTypeInfo().Assembly; + using var stream = assembly.GetManifestResourceStream("Controls.TestCases.HostApp.Resources.Images.royals.png"); + return await Task.FromResult(PlatformImage.FromStream(stream)); + } + + async void OnDownSize(object sender, EventArgs e) + { + var image = await LoadImageAsync(); + var res = image.Downsize(10); + + UpdateStatusLabels(res); + } + + void UpdateStatusLabels(IImage resultImage) + { + _convertedImageStatusLabel.Text = TryAccessImage(resultImage) + ? "Success" + : "Failure"; + } + + bool TryAccessImage(IImage downsizedImage) + { + if (Math.Round(downsizedImage.Width) == 10 && Math.Round(downsizedImage.Height) == 8) + { + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Resources/Images/royals.png b/src/Controls/tests/TestCases.HostApp/Resources/Images/royals.png new file mode 100644 index 000000000000..c2c29a644799 Binary files /dev/null and b/src/Controls/tests/TestCases.HostApp/Resources/Images/royals.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30006.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30006.cs new file mode 100644 index 000000000000..0386ad27618b --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30006.cs @@ -0,0 +1,27 @@ +#if TEST_FAILS_ON_WINDOWS // Issue Link - https://github.com/dotnet/maui/issues/16767 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue30006 : _IssuesUITest +{ + public Issue30006(TestDevice device) : base(device) + { + } + + public override string Issue => "The downsized image continues to retain its original dimensions"; + + [Test] + [Category(UITestCategories.GraphicsView)] + public void VerifyDownsizedImageHasNewDimensions() + { + App.WaitForElement("ConvertedImage"); + App.Tap("Issue30006DownSizeBtn"); + + var downsizedLabelText = App.FindElement("ConvertedImage").GetText(); + Assert.That(downsizedLabelText, Is.EqualTo("Success")); + } +} +#endif \ No newline at end of file diff --git a/src/Graphics/src/Graphics/Platforms/iOS/UIImageExtensions.cs b/src/Graphics/src/Graphics/Platforms/iOS/UIImageExtensions.cs index ab9d9268e597..76371a02b502 100644 --- a/src/Graphics/src/Graphics/Platforms/iOS/UIImageExtensions.cs +++ b/src/Graphics/src/Graphics/Platforms/iOS/UIImageExtensions.cs @@ -27,7 +27,7 @@ public static UIImage ScaleImage(this UIImage target, float maxWidth, float maxH public static UIImage ScaleImage(this UIImage target, CGSize size, bool disposeOriginal = false) { - using (var renderer = new UIGraphicsImageRenderer(target.Size)) + using (var renderer = new UIGraphicsImageRenderer(size)) { var resultImage = renderer.CreateImage((UIGraphicsImageRendererContext imageContext) => {