Skip to content

Conversation

@SyedAbdulAzeemSF4852
Copy link
Contributor

@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 commented Jul 2, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

  • When an image is downsized on iOS, the resulting image appears upside down and is also scaled.

Root Cause

Scaling Issue :

  • The UIGraphicsImageRenderer constructor without format defaults to Scale=0 (device scale), causing the same downsizing operation to produce different pixel dimensions on different devices (1x/2x/3x scale factors), leading to inconsistent image processing results.

Flipping Issue :

  • Core Graphics uses a bottom-left origin, while UIKit uses a top-left origin, so images drawn without adjusting the coordinate system appearing upside down.

Description of Change

  • Included an early return to bypass scaling when the image's current size matches the target size.

Scaling Issue :

  • Explicitly controlled scale factor to preserve original image characteristics.
  • Setting Scale = target.CurrentScale maintains the original image's pixel density, preventing device-specific scaling from being applied.

Flipping Issue:

  • Replaced CGContext's DrawImage method with UIImage's Draw method, which utilizes UIKit’s top-left coordinate system.
  • This change ensures the image is rendered with the correct orientation, eliminating the need for manual flipping or coordinate adjustments.

Issues Fixed

Fixes #30350

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before After

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jul 2, 2025
@sheiksyedm sheiksyedm added area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/ios labels Jul 2, 2025
@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 marked this pull request as ready for review July 2, 2025 13:57
Copilot AI review requested due to automatic review settings July 2, 2025 13:57
@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 requested a review from a team as a code owner July 2, 2025 13:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes inconsistent scaling and upside-down rendering when downsizing UIImage on iOS and Mac by explicitly setting the renderer’s scale and correcting the Core Graphics coordinate system, and adds UI tests to validate the fix.

  • Explicitly set UIGraphicsImageRendererFormat.Scale to target.CurrentScale to preserve pixel density.
  • Adjust Core Graphics transforms to align the origin with UIKit’s top-left.
  • Added shared and host-app UI tests to verify that a downsized image renders right-side up.

Reviewed Changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

File Description
src/Graphics/src/Graphics/Platforms/iOS/UIImageExtensions.cs Added renderer format with explicit scale and CTM adjustments for flipping
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30350.cs Introduced a shared UI test to verify the downsized image isn’t flipped
src/Controls/tests/TestCases.HostApp/Issues/Issue30350.cs Added host app sample page and label/Image setup for the issue
Comments suppressed due to low confidence (2)

src/Controls/tests/TestCases.HostApp/Issues/Issue30350.cs:40

  • Avoid using async void for InitAsync; consider returning a Task and invoking it in OnAppearing or an async lifecycle method so you can await it and catch exceptions.
	private async void InitAsync()

src/Controls/tests/TestCases.HostApp/Issues/Issue30350.cs:29

  • You assign downsizedSizeLabel and downsizedSource after setting Content, but neither the Label nor Image will update automatically. Use data binding or update the UI elements on the main thread after loading completes.
				new Label

@hflexgrig
Copy link

Is there any prerelease build available for this PR? I'd like to check on my app how it behaves..

@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jul 2, 2025
@PureWeen PureWeen added the i/regression This issue described a confirmed regression on a currently supported version label Jul 2, 2025
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Jul 2, 2025
@PureWeen PureWeen requested review from jsuarezruiz and removed request for rmarinho July 2, 2025 20:32
@PureWeen
Copy link
Member

PureWeen commented Jul 2, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Jul 3, 2025
@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Jul 3, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Jul 4, 2025
@PureWeen PureWeen removed p/0 Current heighest priority issues that we are targeting for a release. i/regression This issue described a confirmed regression on a currently supported version labels Jul 10, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 11, 2025
{
downsizedImage = new Image
{
Aspect = Aspect.AspectFit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug in iOS: #30465 (comment)

So maybe use Center and then re-enable for all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattleibow , Based on the suggestion, I replaced AspectFit with AspectCenter. However, the behavior is still inconsistent across platforms. For your reference, I’ve attached the relevant screenshots below.

Android Windows Mac iOS

@@ -0,0 +1,24 @@
#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS // Issue Link - https://github.com/dotnet/maui/issues/30465
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug in iOS I think: #30465 (comment). We should use center and just try running everywhere again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattleibow , As suggested, I’ve used Aspect.Center and shared my analysis in this comment.

@jsuarezruiz
Copy link
Contributor

@SyedAbdulAzeemSF4852 COuld you rebase and fix the conflict?

@SyedAbdulAzeemSF4852
Copy link
Contributor Author

@SyedAbdulAzeemSF4852 COuld you rebase and fix the conflict?

@jsuarezruiz , Since the revert PR #30421 has been merged and the issue no longer reproduces with that fix, my changes are no longer necessary. Therefore, I’m closing this PR.

@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Jul 29, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

IImage downsize broken starting from 9.0.80 and not fixed in 9.0.81

6 participants