How to know the width and height in pixels of a given image programmatically

Platform: ASP.NET| Category: Miscellaneous

You will have to create a Bitmap instance from the image file and then query the Width and Height as follows:

VB.NET


Dim bm As Bitmap = New Bitmap(Server.MapPath('b2346.jpg'))
Response.Write('Height  :' + bm.Height.ToString())
Response.Write('<br> Width :' + bm.Width.ToString())

C#


Bitmap bm = new Bitmap( Server.MapPath('b2346.jpg'));
Response.Write ('Height  :' + bm.Height.ToString() );
Response.Write ('<br> Width :' +bm.Width.ToString() );

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.