DarkW1nter
DarkW1nter

Reputation: 2841

xamarin forms - work out dimensions of an image source using c#

In Xamarin Forms, using C# is there a way to get the dimensions of the source of an image before you render it to the page?

I want to be able to display images in either portrait or landscape depending on how the source image looks, and the only way I can think of to determine that is to work out the source dimension, unless there is another way to go about it?

Upvotes: 1

Views: 602

Answers (1)

DarkW1nter
DarkW1nter

Reputation: 2841

Found it here, as I'm using FFImageLoading I can do this:

var cachedImage = new CachedImage() {
    WidthRequest = 300,
    HeightRequest = 300,
    DownsampleToViewSize = true, };

cachedImage.Success += (sender, e) => {
    var h = e.ImageInformation.OriginalHeight;
    var w = e.ImageInformation.OriginalWidth; };

Upvotes: 1

Related Questions