Repository: dotnet/maui
File: src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs (C#)

Code before:
				var targetWidth = factor * Width;
				var targetHeight = factor * Height;
				return ResizeInternal(targetWidth, targetHeight, 0, 0, targetWidth, targetHeight, disposeOriginal);
			}

			return this;
		}

		public IImage Downsize(float maxWidth, float maxHeight, bool disposeOriginal = false)
		{
			return ResizeInternal(maxWidth, maxHeight, 0, 0, maxWidth, maxHeight, disposeOriginal);
		}

		
		IImage ResizeInternal(float canvasWidth, float canvasHeight, float drawX, float drawY, float drawWidth, float drawHeight, bool disposeOriginal)
		{ 
			using var renderTarget = new CanvasRenderTarget(_creator, canvasWidth, canvasHeight, _bitmap.Dpi);

			using (var drawingSession = renderTarget.CreateDrawingSession())
			{
				drawingSession.DrawImage(_bitmap, new global::Windows.Foundation.Rect(drawX, drawY, drawWidth, drawHeight));
			}

			using (var resizedStream = new InMemoryRandomAccessStream())
			{
				AsyncPump.Run(async () => await renderTarget.SaveAsync(resizedStream, CanvasBitmapFileFormat.Png));
				resizedStream.Seek(0);

				var newImage = FromStream(resizedStream.AsStreamForRead());

				if (disposeOriginal)
				{
					_bitmap.Dispose();
				}

				return newImage;
			}
		}

		public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMode.Fit,
			bool disposeOriginal = false)
		{
			// Calculate scaling factors
			float scaleX = width / Width;
			float scaleY = height / Height;

			float targetWidth = Width;
			float targetHeight = Height;
			float offsetX = 0;
			float offsetY = 0;


Review comment (suggestion):
In #23824, a `AsyncPump.Run` call was removed and it is not [needed](https://github.com/dotnet/maui/pull/23824#issue-2429404698). I believe it should be possible to mimick what was done here: 

https://github.com/dotnet/maui/pull/23824/files#diff-7809b7d3f7611c78ba9e346d0e686e7f564ec68d1c25bc19bee122f9f9f1439dR179-R180

Code after:
				var targetWidth = factor * Width;
				var targetHeight = factor * Height;
				return ResizeInternal(targetWidth, targetHeight, 0, 0, targetWidth, targetHeight, disposeOriginal);
			}

			return this;
		}

		public IImage Downsize(float maxWidth, float maxHeight, bool disposeOriginal = false)
		{
			return ResizeInternal(maxWidth, maxHeight, 0, 0, maxWidth, maxHeight, disposeOriginal);
		}

		
		IImage ResizeInternal(float canvasWidth, float canvasHeight, float drawX, float drawY, float drawWidth, float drawHeight, bool disposeOriginal)
		{ 
			using var renderTarget = new CanvasRenderTarget(_creator, canvasWidth, canvasHeight, _bitmap.Dpi);

			using (var drawingSession = renderTarget.CreateDrawingSession())
			{
				drawingSession.DrawImage(_bitmap, new global::Windows.Foundation.Rect(drawX, drawY, drawWidth, drawHeight));
			}

			using (var resizedStream = new InMemoryRandomAccessStream())
			{
				var saveCompletedEvent = new ManualResetEventSlim(false);
				Exception saveException = null;

				// Start the async save operation
				var saveTask = renderTarget.SaveAsync(resizedStream, CanvasBitmapFileFormat.Png).AsTask();

				saveTask.ContinueWith(task =>
				{
					if (task.Exception is not null)
					{
						saveException = task.Exception;
					}
					// Signal that the operation is complete
					saveCompletedEvent.Set();
				});

				// Wait for the signal
				saveCompletedEvent.Wait();

				// Check for any exceptions during the async operation
				if (saveException is not null)
				{
					throw saveException;
				}
				
				resizedStream.Seek(0);