Reputation: 6846
I have an Image, which I need to scale based on the image's pixel values. When I create the bitmapImage, the pixels (height and width) are both 0.
Is there a way to get height and width before the image is drawn to the canvas?
Upvotes: 3
Views: 917
Reputation: 1956
I had a similar issue where I needed to measure the height of a row (with content) being added to a Grid before adding it to the Grid. Short answer - it can't be done.
Long answer - it can be done. In my code-behind, I created a dummy Grid not a part of the UI. I would add the row to it, and then call .Measure on the dummy Grid that would give me the rendered size of the row. Then I could just add the row to the actual Grid on the UI.
I suspect you could try the same approach with your image. Create a dummy Canvas, add the image to the Canvas, and see how big it is.
Upvotes: 1