Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to get an original image size?

$
0
0

Hi! I have the very basic case, but can't find elegant solution: need to know original image size for layout. But after loading an image to Image view I get -1 value for its width and height.

Here's a code sample, what I'm trying:

var icon = new Image {
    Source = ImageSource.FromFile("icon-edit.png")
};

// This will output -1 values for width and width request
Console.WriteLine("Width={0}, WidthRequest={1}", icon.Width, icon.WidthRequest);

// Adding to relative layout, won't work as expected! Icon's width is calculated as -1.
Children.Add(editIcon,
    Constraint.RelativeToParent((parent) => (parent.Width - icon.Width) / 2),
    Constraint.Constant(10)
);

In the example above icon should be centered horizontally and I could achieve that in some other way. But actually I'll need more sophisticated layout, that's why I need to know image width.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>