Skip to content

[iOS] MediaPicker ShouldUsePngFormat method has conflicting/redundant code #33119

@MitchBomcanhao

Description

@MitchBomcanhao

Description

in src/Essentials/src/MediaPicker/MediaPicker.ios.cs#L611 you can see the following:

		bool ShouldUsePngFormat()
		{
			// Use PNG if:
			// 1. High quality (>=90) and no resizing needed (preserves original format)
			// 2. Original file was PNG
			// 3. Image might have transparency (PNG supports alpha channel)

			bool highQualityNoResize = compressionQuality >= 90 && !maximumWidth.HasValue && !maximumHeight.HasValue;
			bool originalWasPng = !string.IsNullOrEmpty(originalFileName) &&
									(originalFileName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
									 originalFileName.EndsWith(".PNG", StringComparison.OrdinalIgnoreCase));

			// For very high quality or when original was PNG, preserve PNG format
			return (compressionQuality >= 95 && !maximumWidth.HasValue && !maximumHeight.HasValue) || originalWasPng;
		}
  • the check for highQualityNoResize is then discarded and computed again
  • the compressionQuality value is initially checked at 90%, then replaced with 95% in the second computation . which one is it? the comment matches the 90% one.
  • there are two different checks for originalFileName.EndsWith, with different casings of the same string, with an OrdinalIgnoreCase string comparer, so they're both effectively the same thing.

Lastly, this magical compression figure over which the PNG file format is used is rather unexpected. I didn't expect to have to inspect the maui source code to figure this out.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

10.0.11

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

Labels

area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infogood first issueGood for newcomersplatform/ioss/triagedIssue has been reviewedt/bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions