[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

ASP.NET how to Get Image Height as an Integer

Given the control Image1.  How do I get its height as an integer?

Dim Height as Integer = Image1.Height

fails with the error "value of type 'System.Web.Ui.Webcontrols.Unit' cannot be converted to 'Integer'

I need the height in an integer format so that I can use a formula to change it.
1 Solution

The Height and Width of an image are stored as a Unit structure.

The Unit defines not only a value for the height/width but a UnitType (pixel, pica, percentage, em etc).

You need to use the Value property to get the length of the measurement (as a double) :

Dim Height as Integer = CInt(Image1.Height.Value)

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now