-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android, iOS] Fix for the Resize method does not dispose the original image, even when disposeOriginal is set to true #29936
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
PureWeen
merged 3 commits into
dotnet:inflight/current
from
SyedAbdulAzeemSF4852:fix-21886
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2dc3bb8
Fix for original image disposal when disposeOriginal is true in Resi…
SyedAbdulAzeemSF4852 064d0e6
Updated the fix for iOS, and modified the test case to reflect the c…
SyedAbdulAzeemSF4852 c1852f7
Updated the issue link in test case
SyedAbdulAzeemSF4852 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System.Reflection; | ||
| using Microsoft.Maui.Graphics.Platform; | ||
| using IImage = Microsoft.Maui.Graphics.IImage; | ||
|
|
||
| namespace Controls.TestCases.HostApp.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 21886, "The original image remains undisposed even after setting disposeOriginal to true in the Resize and Downsize methods", PlatformAffected.Android | PlatformAffected.iOS)] | ||
| public class Issue21886 : ContentPage | ||
| { | ||
| Label _originalImageStatusLabel; | ||
|
|
||
| public Issue21886() | ||
| { | ||
| _originalImageStatusLabel = new Label | ||
| { | ||
| AutomationId = "OriginalImageStatusLabel", | ||
| Text = "Status of Original Image Disposal" | ||
| }; | ||
|
|
||
| VerticalStackLayout stackLayout = new VerticalStackLayout | ||
| { | ||
| Children = | ||
| { | ||
| CreateButton("Resize", OnResize), | ||
| CreateButton("DownSize", OnDownSize), | ||
| _originalImageStatusLabel, | ||
| } | ||
| }; | ||
|
|
||
| Content = new ScrollView { Content = stackLayout }; | ||
| } | ||
|
|
||
| Button CreateButton(string text, EventHandler handler) | ||
| { | ||
| Button button = new Button | ||
| { | ||
| AutomationId = $"Issue21886{text}Btn", | ||
| 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 OnResize(object sender, EventArgs e) | ||
| { | ||
| var image = await LoadImageAsync(); | ||
| var res = image.Resize(10, 10, ResizeMode.Fit, true); | ||
|
|
||
| UpdateStatusLabels(res, image, "Resize"); | ||
| } | ||
|
|
||
| async void OnDownSize(object sender, EventArgs e) | ||
| { | ||
| var image = await LoadImageAsync(); | ||
| var res = image.Downsize(10, 10, true); | ||
|
|
||
| UpdateStatusLabels(res, image, "Downsize"); | ||
| } | ||
|
|
||
| void UpdateStatusLabels(IImage resultImage, IImage originalImage, string operation) | ||
| { | ||
| _originalImageStatusLabel.Text = TryAccessImage(originalImage) | ||
| ? "Success" | ||
| : originalImage.Width == 0 && originalImage.Height == 0 ? "Success" : "Failure"; | ||
| } | ||
|
|
||
| bool TryAccessImage(IImage image) | ||
| { | ||
| try | ||
| { | ||
| var _ = image.Width; | ||
| return false; | ||
| } | ||
| catch (ObjectDisposedException) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions
32
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21886.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #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 Issue21886 : _IssuesUITest | ||
| { | ||
| public Issue21886(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "The original image remains undisposed even after setting disposeOriginal to true in the Resize and Downsize methods"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.GraphicsView)] | ||
| public void VerifyOriginalImageBeingDisposed() | ||
| { | ||
| App.WaitForElement("OriginalImageStatusLabel"); | ||
| App.Tap("Issue21886ResizeBtn"); | ||
|
|
||
| var resizeLabelText = App.FindElement("OriginalImageStatusLabel").GetText(); | ||
| Assert.That(resizeLabelText, Is.EqualTo("Success")); | ||
|
|
||
| App.Tap("Issue21886DownSizeBtn"); | ||
|
|
||
| var downsizeLabelText = App.FindElement("OriginalImageStatusLabel").GetText(); | ||
| Assert.That(downsizeLabelText, Is.EqualTo("Success")); | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.