-
Notifications
You must be signed in to change notification settings - Fork 678
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 reports PixelWidth & PixelHeight as zero. #10149
Comments
The image must have been loaded.
|
@castorix I don't see how this is different to my usage. But after I set a BitmapImage as source, the PixelWidth and PixelHeight are still zero.
Is it the case that UIElement resources are not built untill they are added to the live tree? ... No, I just tested, and even setting the BitmapImage as source to a live Image, as you do, does not set the Width & Height. Update: With further thought. I guess the tree isn't actually live, just because I've declared it in Xaml, and set the source. The tree must be loaded later on. |
Wow, the way they've done it seems pretty complicated to me. The image meta-data tells you the size of the image before you even load it, or the image object itself when built. That is a dependable value and always available. Having an event as the only way to access it makes it complicated. For example. I just wrote some code that uses the ImageOpened events to check image sizes. And the events don't ever trigger. So ... have they already triggered before I subscribe to the event. This seems like unnecessary complication. How do we subscribe to the events before they trigger? I've already got the code in the MainWindow constructor. Update: Because the images I'm checking are drag and drop, they don't actually get built until the very moment the drag operation starts. Arrrrgh. I just want to check the image sizes when the application starts, not piecemeal at random other times. Doesn't it seem just so simple to load the images and make their sizes available when I construct the images? The simplification I can make in regard to drag-n-drop is that when the object is picked up, I can get the size at that moment and store the value globally since there is only a single object being dragged at a time. - Update - nope, that won't work, because the ImageOpened event only triggers the first time that particular image is opened. So I would have to record separate sizes for every image. The ImageOpened event triggers after DragStarting event - where I need the image size. That's a catch 22 - and not a great approach to API design - what am I not understanding? |
@Gavin-Williams I'm not 100% sure how your project is set up and when/where you need the values, but with you mentioning needing the size with a DragStarting event, you can get the pixel values in that event as follows.
|
Describe the bug
BitmapImage reports PixelWidth & PixelHeight as zero.
Steps to reproduce the bug
This seems to be a permanent issue.
Expected behavior
I expect PixelWidth & PixelHeight to report the size as presented.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
The text was updated successfully, but these errors were encountered: