Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

BitmapImage doesn't use logical pixels when decoding a stream #6257

Closed
1 of 2 tasks
FrayxRulez opened this issue Nov 8, 2021 · 5 comments
Closed
1 of 2 tasks

BitmapImage doesn't use logical pixels when decoding a stream #6257

FrayxRulez opened this issue Nov 8, 2021 · 5 comments
Labels
area-Images Images, SVG bug Something isn't working product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team

Comments

@FrayxRulez
Copy link

Describe the bug

Currently, setting DecodePixelType = DecodePixelType.Logical doesn't seem to make any difference in a WinUI 3 desktop application.

Steps to reproduce the bug

  1. Set the monitor display to a scaling that's not 100%.
  2. Create a new BitmapImage, specifying DecodePixelWidth and DecodePixelHeight.
  3. DecodePixelType = DecodePixelType.Logical.
  4. Display the bitmap in the UI.
  5. Notice the blur.

Expected behavior

BitmapImage will scale decode pixel width and height accordingly to the monitor scaling when pixel type is set to logical.

Screenshots

Here's a comparison between UWP on the left and WinUI 3 on the right:
image

NuGet package version

WinUI 3 - Windows App SDK 0.8: 0.8.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

Insider Build (xxxxx)

Additional context

No response

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 8, 2021
@codendone codendone added area-Images Images, SVG bug Something isn't working product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team and removed needs-triage Issue needs to be triaged by the area owners labels Nov 9, 2021
@DL444
Copy link

DL444 commented Jul 3, 2022

Still experiencing this problem in Windows App SDK v1.1.2.

Also note that DisplayInformation APIs are currently not available in Windows App SDK since they require a CoreWindow. See microsoft/WindowsAppSDK#1609.

I eventually resorted to calling Win32 APIs directly to get the scaling factor and multiply it with the desired logical pixel size to get the corresponding physical pixel size, and then assign that to DecodePixelWidth. I'll post my code here for reference.

using System;
using System.Runtime.InteropServices;
using WinRT.Interop;

public static double GetWindowScaleFactor(Window window)
{
    IntPtr hwnd = WindowNative.GetWindowHandle(window);
    IntPtr hMon = MonitorFromWindow(hwnd, 1);
    int hresult = GetScaleFactorForMonitor(hMon, out int scale);
    return hresult == 0 ? scale / 100.0 : 0;
}

[DllImport("User32.dll")]
private static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);

[DllImport("Shcore.dll")]
private static extern int GetScaleFactorForMonitor(IntPtr hMon, out int pScale);

@Marv51
Copy link
Contributor

Marv51 commented Dec 20, 2022

This issue is still present in WinAppSDK 1.2.2.

DecodePixelType.Logical is basically just ignored.

This results in DecodePixelWidth/Height being very inconvenient to use. As it can only be set in code and calculations with current DPI are needed.

Seems like this was deactivated during the transition to 3.0 and not fixed afterwards?

I wonder if this is tracked internally? I wonder who would know, maybe @codendone?

@DominicMaas
Copy link

I've hit this as well. Giving it a bump.

@bpulliam
Copy link
Contributor

This issue should be fixed in WinAppSDK 1.3.

@JJBrychell
Copy link

It looks like the fix may not have made it into 1.3, but it is in1.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Images Images, SVG bug Something isn't working product-winui3 WinUI 3 issues team-Rendering Issue for the Rendering team
Projects
None yet
Development

No branches or pull requests

7 participants