Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3bfe46
Fix for GraphicsView ImagePaint
HarishwaranVijayakumar Apr 7, 2025
f69f8be
update for the graphics view imagePaint
HarishwaranVijayakumar Apr 7, 2025
ef22fa8
Added testcase
HarishwaranVijayakumar Apr 7, 2025
4a7ad8d
Implementation for Downsize
HarishwaranVijayakumar Apr 8, 2025
87e655d
Revert "Added testcase"
HarishwaranVijayakumar Apr 8, 2025
a79de0d
Added test case
HarishwaranVijayakumar Apr 8, 2025
6ad14d0
Added CreateResizedMethod
HarishwaranVijayakumar Apr 9, 2025
c08e5a8
Implemented Resize method
HarishwaranVijayakumar Apr 9, 2025
1177737
Fix modification
HarishwaranVijayakumar Apr 9, 2025
88f5bad
Added testcase
HarishwaranVijayakumar Apr 10, 2025
db4d60d
Revert "Added test case"
HarishwaranVijayakumar Apr 10, 2025
90207ff
Updated the changes
HarishwaranVijayakumar Apr 10, 2025
08a978f
Update changes
HarishwaranVijayakumar Apr 10, 2025
d62deda
Updated the testcase
HarishwaranVijayakumar Apr 10, 2025
db62dd7
Commited the changes
HarishwaranVijayakumar Apr 10, 2025
d93fbe7
Updating code
HarishwaranVijayakumar Apr 23, 2025
1b608b5
Update TestCase
HarishwaranVijayakumar Apr 23, 2025
6f7534f
Code Update
HarishwaranVijayakumar Apr 23, 2025
e05ce14
Modify TestCase
HarishwaranVijayakumar Apr 24, 2025
6f9535a
TestCase Updation
HarishwaranVijayakumar Apr 24, 2025
4117eda
Code update
HarishwaranVijayakumar Apr 25, 2025
d67957a
Adding Snapshots
HarishwaranVijayakumar Apr 28, 2025
cac6f45
Added snapshots
HarishwaranVijayakumar May 2, 2025
d5e29f3
Revert "Added snapshots"
HarishwaranVijayakumar May 2, 2025
08c5e35
Refactor code
HarishwaranVijayakumar May 12, 2025
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Expand Up @@ -66,6 +66,7 @@
<MauiFont Include="Resources\Fonts\**" />
<MauiFont Remove="Resources\Fonts\Dokdo-Regular.ttf" />
<EmbeddedResource Include="Resources\Fonts\Dokdo-Regular.ttf" />
<EmbeddedResource Include="Resources\Images\royals.png" />
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

Expand Down
79 changes: 79 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16767_Downsize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Reflection;
using Maui.Controls.Sample.Issues;
using Microsoft.Maui.Graphics.Platform;
using IImage = Microsoft.Maui.Graphics.IImage;

namespace Controls.TestCases.HostApp.Issues;

[Issue(IssueTracker.Github, 28725, "Downsize function in W2DImage class", PlatformAffected.UWP)]

public class Issue16767_DownSize : TestContentPage
{
GraphicsView downSizeGraphicsView;
Issue16767_DownsizeDrawable downSizeDrawable;

protected override void Init()
{
var rootLayout = new VerticalStackLayout();

downSizeGraphicsView = new GraphicsView()
{
BackgroundColor = Colors.Red,
HeightRequest = 400,
WidthRequest = 400
};

Label descriptionLabel = new Label()
{
Text = "The test should pass if the image is displayed and resized correctly. If the image is not displayed or not downsized correctly, the test has failed.",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "descriptionLabel"
};

downSizeDrawable = new Issue16767_DownsizeDrawable();
downSizeGraphicsView.Drawable = downSizeDrawable;
rootLayout.Add(downSizeGraphicsView);

rootLayout.Add(descriptionLabel);
Content = rootLayout;
}
}

public class Issue16767_DownsizeDrawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
IImage image;
var assembly = GetType().GetTypeInfo().Assembly;
using (var stream = assembly.GetManifestResourceStream("Controls.TestCases.HostApp.Resources.Images.royals.png"))
{
image = PlatformImage.FromStream(stream);
}
if (image is not null)
{
float spacing = 20;
float currentY = 0;

canvas.FontColor = Colors.Black;
canvas.FontSize = 16;

// Label before first image
canvas.DrawString("Downsize (100, 200)", 0, currentY, dirtyRect.Width, 30, HorizontalAlignment.Left, VerticalAlignment.Top);
currentY += 30;

var downsized1 = image.Downsize(100, 200);
canvas.SetFillImage(downsized1);
canvas.FillRectangle(0, currentY, 240, downsized1.Height);
currentY += downsized1.Height + spacing;

// Label before second image
canvas.DrawString("Downsize (100)", 0, currentY, dirtyRect.Width, 30, HorizontalAlignment.Left, VerticalAlignment.Top);
currentY += 30;

var downsized2 = image.Downsize(100);
canvas.SetFillImage(downsized2);
canvas.FillRectangle(0, currentY, 240, downsized2.Height);
}
}
}
114 changes: 114 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16767_Resize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System.Reflection;
using Maui.Controls.Sample.Issues;
using Microsoft.Maui.Graphics.Platform;
using IImage = Microsoft.Maui.Graphics.IImage;

namespace Controls.TestCases.HostApp.Issues;

[Issue(IssueTracker.Github, 16767, "Resize function in W2DImage class", PlatformAffected.UWP)]

public class Issue16767_Resize : TestContentPage
{
GraphicsView ReSizeGraphicsView;
Issue16767_ResizeDrawable resizeDrawable;

RadioButton resizeModeFit;
RadioButton resizeModeBleed;
RadioButton resizeModeStretch;
protected override void Init()
{

var rootLayout = new VerticalStackLayout();

ReSizeGraphicsView = new GraphicsView()
{
HeightRequest = 300,
WidthRequest = 300
};
resizeDrawable = new Issue16767_ResizeDrawable();
ReSizeGraphicsView.Drawable = resizeDrawable;
rootLayout.Add(CreateResizeModeSelection());
rootLayout.Add(ReSizeGraphicsView);
Content = rootLayout;
}

HorizontalStackLayout CreateResizeModeSelection()
{
var horizontalStackLayout = new HorizontalStackLayout()
{
Spacing = 10,
};

resizeModeFit = CreateRadioButton("Fit", "ResizeModeSelection", true, "ResizeModeFit");
resizeModeBleed = CreateRadioButton("Bleed", "ResizeModeSelection", false, "ResizeModeBleed");
resizeModeStretch = CreateRadioButton("Stretch", "ResizeModeSelection", false, "ResizeModeStretch");

resizeModeFit.CheckedChanged += OnResizeModeChanged;
resizeModeBleed.CheckedChanged += OnResizeModeChanged;
resizeModeStretch.CheckedChanged += OnResizeModeChanged;

horizontalStackLayout.Children.Add(resizeModeFit);
horizontalStackLayout.Children.Add(resizeModeBleed);
horizontalStackLayout.Children.Add(resizeModeStretch);

return horizontalStackLayout;
}

RadioButton CreateRadioButton(string text, string groupName, bool isChecked, string automationID)
{
return new RadioButton
{
Content = text,
GroupName = groupName,
IsChecked = isChecked,
FontSize = 11,
AutomationId = automationID
};
}

void OnResizeModeChanged(object sender, CheckedChangedEventArgs e)
{
if (resizeModeFit.IsChecked)
{
resizeDrawable.SetResizeMode(ResizeMode.Fit);
ReSizeGraphicsView.Invalidate();
}
else if (resizeModeBleed.IsChecked)
{
resizeDrawable.SetResizeMode(ResizeMode.Bleed);
ReSizeGraphicsView.Invalidate();
}
else if (resizeModeStretch.IsChecked)
{
resizeDrawable.SetResizeMode(ResizeMode.Stretch);
ReSizeGraphicsView.Invalidate();
}
}
}

public class Issue16767_ResizeDrawable : IDrawable
{
ResizeMode _resizeMode;

internal void SetResizeMode(ResizeMode resizeMode)
{
_resizeMode = resizeMode;
}

public void Draw(ICanvas canvas, RectF dirtyRect)
{
IImage image;
var assembly = GetType().GetTypeInfo().Assembly;
using (var stream = assembly.GetManifestResourceStream("Controls.TestCases.HostApp.Resources.Images.royals.png"))
{
image = PlatformImage.FromStream(stream);
}

if (image is not null)
{
var resizedImage = image.Resize(100, 200, _resizeMode);
canvas.SetFillImage(resizedImage);
canvas.FillRectangle(0, 0, 200, resizedImage.Height);
}
}
}
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,23 @@
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS //NullReferenceException throws on iOS and mac Issue link - https://github.com/dotnet/maui/issues/19642
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue16767_Downsize : _IssuesUITest
{
public Issue16767_Downsize(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Downsize function in W2DImage class";

[Test]
[Category(UITestCategories.GraphicsView)]
public void ImagePaintWithDownsize()
{
App.WaitForElement("descriptionLabel");
VerifyScreenshot();
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS //NullReferenceException throws on iOS and mac Issue link - https://github.com/dotnet/maui/issues/19642
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue16767_Resize : _IssuesUITest
{
public Issue16767_Resize(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Resize function in W2DImage class";

[Test]
[Category(UITestCategories.GraphicsView)]
public void ImagePaintWithResizeModeFit()
{
App.WaitForElement("ResizeModeFit");
VerifyScreenshot();
}

[Test]
[Category(UITestCategories.GraphicsView)]
public void ImagePaintWithResizeModeBleed()
{
App.WaitForElement("ResizeModeBleed");
App.Tap("ResizeModeBleed");
VerifyScreenshot();
}

[Test]
[Category(UITestCategories.GraphicsView)]
public void ImagePaintWithResizeModeStretch()
{
App.WaitForElement("ResizeModeStretch");
App.Tap("ResizeModeStretch");
VerifyScreenshot();
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Expand Up @@ -390,7 +390,7 @@ public override void SetFillPaint(Paint paint, RectF rectangle)

if (paint is ImagePaint imagePaint)
{
if (imagePaint.Image is PlatformImage image)
if (imagePaint.Image is Platform.PlatformImage image)
{
var bitmapBrush = new CanvasImageBrush(_session, image.PlatformRepresentation)
{
Expand Down
Loading
Loading