Skip to content

[iOS, Mac] Fix for downsized image retaining original dimensions in GraphicsView #30007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<MauiFont Remove="Resources\Fonts\Dokdo-Regular.ttf" />
<EmbeddedResource Include="Resources\Fonts\Dokdo-Regular.ttf" />
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
<EmbeddedResource Include="Resources\Images\royals.png" />
</ItemGroup>

<ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30006.cs
Original file line number Diff line number Diff line change
@@ -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<IImage> 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;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down
Loading