Skip to content

Fix ArgumentException with FromWidth/Height options in InteropBitmap #10706

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -189,25 +189,21 @@ public static BitmapSizeOptions FromRotation(Rotation rotation)

// Note: In this method, newWidth, newHeight are not affected by the
// rotation angle.
internal void GetScaledWidthAndHeight(
uint width,
uint height,
out uint newWidth,
out uint newHeight)
internal void GetScaledWidthAndHeight(uint width, uint height, out uint newWidth, out uint newHeight)
{
if (_pixelWidth == 0 && _pixelHeight != 0)
{
Debug.Assert(_preservesAspectRatio == true);

newWidth = (uint)((_pixelHeight * width)/height);
newWidth = (uint)((_pixelHeight * width) / height);
newHeight = (uint)_pixelHeight;
}
else if (_pixelWidth != 0 && _pixelHeight == 0)
{
Debug.Assert(_preservesAspectRatio == true);

newWidth = (uint)_pixelWidth;
newHeight = (uint)((_pixelWidth * height)/width);
newHeight = (uint)((_pixelWidth * height) / width);
}
else if (_pixelWidth != 0 && _pixelHeight != 0)
{
Original file line number Diff line number Diff line change
@@ -368,17 +368,21 @@ internal override void FinalizeCreation()
if (_sizeOptions.DoesScale)
{
Debug.Assert(_sizeOptions.Rotation == Rotation.Rotate0);

uint width, height;

_sizeOptions.GetScaledWidthAndHeight(
(uint)_sizeOptions.PixelWidth,
(uint)_sizeOptions.PixelHeight,
out width,
out height);
// In case the source clip is Int32.Empty but we're asked to scale, we must scale the original source values
if (_sourceRect.IsEmpty)
{
HRESULT.Check(UnsafeNativeMethods.WICBitmapSource.GetSize(_unmanagedSource, out width, out height));
_sizeOptions.GetScaledWidthAndHeight(width, height, out width, out height);
}
else
{
_sizeOptions.GetScaledWidthAndHeight((uint)_sourceRect.Width, (uint)_sourceRect.Height, out width, out height);
}

HRESULT.Check(UnsafeNativeMethods.WICImagingFactory.CreateBitmapScaler(
wicFactory,
out wicTransformer));
HRESULT.Check(UnsafeNativeMethods.WICImagingFactory.CreateBitmapScaler(wicFactory, out wicTransformer));

lock (_syncObject)
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DeleteObject
DestroyIcon
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@
<MicrosoftPrivateWinFormsReference Include="System.Private.Windows.Core" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="$(MicrosoftWindowsCsWin32PackageVersion)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" />
Loading