Get Image Size from New Image


I have an application where I have a dropdown box and it fires an event to load a new image from my  SQL Server 2005 database.  I am able to show the image but would like to show the dimensions as a label but not able to do this.

 My code looks like this

//This works fine - can load the image
imgLargePic.ImageUrl = "~/Controls/Fetch_Pic.ashx?ProductPicID=" + iProductPicID + "&Size=Large";

//Can't get this to work... - next line of code...
lblPicSize.Text=imgLargePic.Width.Value.ToString() + "X" + imgLargePic.Height.ToString();

 Any help greatly appreciated.


11/14/2008 6:14:13 PM 93655 articles. 6 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 51
Get it on Google Play
Get it on Apple App Store

You can load the file into a bitmap object:


1    Bitmap image = new Bitmap(path)
3    image.Height
4    image.Width
Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.
11/14/2008 7:01:55 PM

You can add an OnLoad event handler on imgLargePic.

//This works fine - can load the image
imgLargePic.ImageUrl = "~/Controls/Fetch_Pic.ashx?ProductPicID=" + iProductPicID + "&Size=Large";
imgLargePic.OnLoad += FillInTheDimensions();

void FillInTheDimensions()
   lblPicSize.Text=imgLargePic.Width.Value.ToString() + "X" + imgLargePic.Height.ToString();

11/14/2008 7:13:06 PM

 Thanks for both of these approaches - they both seem promising.  However, I have a challenge remaining in that my image control is located inside a Wizard panel that I have been using and I got the error

Cannot access protected member 'System.Web.UI.Control.OnLoad(System.EventArgs)' via a qualifier of type 'System.Web.UI.WebControls.Image'; the qualifier must be of type 'Members_Management_ProductSheetWizard' (or derived from it)

Can you suggest how I might reference the image so that I could use your approach?

Appreciate the help


11/14/2008 9:40:21 PM

Hey, I make a mistake when I told you to use OnLoad... replace OnLoad to Load with the proper eventargs placed inside the  FillInTheDimensions() function (i.e.  FillInTheDimensions(object sender, RoutedEventArgs e); ) <--- probably not the right arguments.

 so it should look something like

    imgLargePic.ImageUrl = "~/Controls/Fetch_Pic.ashx?ProductPicID=" + iProductPicID + "&Size=Large";
    imgLargePic.Load +=new EventHandler(imgLargePic_Load);

void imgLargePic_Load(object sender, EventArgs e)
     lblPicSize.Text=imgLargePic.Width.Value.ToString() + "X" + imgLargePic.Height.ToString(); 

11/14/2008 9:50:46 PM

 Thanks for this - seems to be getting there -  when I get to the imgLargePic.Load +=new EventHandler(imgLargePic_Load); step, it is not firing the imgLargPic_Load function.


11/14/2008 10:53:46 PM

Does it fire or does it seem like it's not firing?  If it isn't firing then perhaps the label isn't loaded yet.  In which case you should update the textbox after the page loads.

 this.LoadComplete += new EventHandler(_Default_LoadComplete);

void _Default_LoadComplete(object sender, EventArgs e)
      lblPicSize.Text = imgLargePic.Width.Value.ToString() ......

11/14/2008 11:22:07 PM

 Hi - it looks like my last post didn't take and I've been getting messages from the system saying that there's a problem.  So here goes again.

I've put  this.LoadComplete += new EventHandler(_Default_LoadComplete); in the PageLoad area and the the _Default_LoadComplete seems to fire after the pageload.  However, I am still getting a zero value for both the height and width attributes of the image are showing as 0.0  and imgLargePic.Width.Value.ToString()  is giving me a 0 value.


11/17/2008 7:36:24 PM

It looks like Erwin21 was right from the beginning.  You can't get the height and width from System.UI.WebControls.Image unless you set it before you get it.  I had to create a project to see for myself.  I don't know how you have your image saved in the database but you will have to get the stream of bytes into an image something like what Erwin said or like

System.Drawing.Image img = System.Drawing.Image.FromStream(databaseImageStream);

Then use img.Height and img.Width to get the actual height and width.

11/17/2008 11:45:19 PM

That's correct, you have to download the picture to the server first to determine the size of it. If you use the image control the picture is downloaded client side and it's impossible to get the size. An other solution can be javascript to get te size of the picture.

Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.
11/18/2008 8:53:18 AM

Similar Artilces:

getting remote image sizes with image::size lwp
I am trying to get the width and height attributes of jpg's and gif's on a remote server. I have found Image::Size and LWP but am unable to put them together so that I can open an http path (e.g. and print out the image size. Any help would be appreciated including where I might go to read more on this. TIA My first attempt that failed: #!/usr/bin/perl # The next few lines use the LWP (Library www perl) module # to read the files via http that each url points to. $the_url =3D '

getting remote image size with Image::Size & LWP
=19 Thank you for your patience and help bringing me up to speed on how to be a better user of this list. My previous post was my first. I am trying to write a script that will use Image::Size module in conjunction with the LWP module to retrieve the height and width attribute of a gif or jpg on a remote server. Below the first script uses the Image::Size module and successfully returns the height and width of an image on the same volume. The second script uses the LWP module and depending on which version of $the_url is used, successfully returns the contents of an html file or an ...

Reading in an image from the web and getting image type
Hi,   I am trying to stream in images from the web and then convert them to byte[] and then plug them into a database "image" field.  I basically have it working but in the end the image is messed up for some reason.  Here is my code:  byte[] returnVal = null;  Stream ImageStream = new WebClient().OpenRead(pageUrl);  int count = 0;while (ImageStream.ReadByte() != -1) count++;   ImageStream.Close();  Stream ImageStream2 = new WebClient().OpenRead(pageUrl); //where pageUrl is the url to the image file  byte[] temp = new byt...

Getting image size without loading the image
Hi, is there anywhere an interface to get the image size from a file without loading the whole image? When I want to display a catalog of images in a directory, I also want to display the size of each image, but do not like to load the images. I just want to get the size as fast as possible. Is there an interface available for this purpose? Georg Georg Maa� wrote: > is there anywhere an interface to get the image size from a file without > loading the whole image? That must be a popular thing to do, someone else also asked for that recently. You can use img...

Images open in new window same size as image only
Hi, I've a page on my website that contains thumbnails of images and when clicked on a new browser window opens with the image showing at full size (whatever that size may be). What I'm trying to do though is get the new window to open up only to the size of the image and no bigger, along with a 'Close' label on the new window. Can any one please help?   Many thanks, James  Doesn't really have much, if anything, to do with ASP.NET, this has to be accomplished with javascript here's a function that can do what you ask:function resizeWindow() {     var iWi...

Make the image box on a web page the size of the image.
The thing I would like to figure out is how to tell the image box on an page to fit to the image and not the other way around. Currently when I have the imageurl load up a picture in the image box it resizes it to the box and distorts the image. I have found the code in the msdn: C#public Size Size { get; } but I don't understand it. Why is Size being used as the name and the data type. I am guessing I would have to acquire the size of the image being loaded and then change the image box to match the width and height dimensions. Unless there is an easier way to do this?&nbs...

Problem making image
I have a Dell Latitude 131L that I am trying to make an image of, but it seems that imaging engine somehow cant find the partition with the OS, so I only get an image with 4k size. Anyone have any ideas to what might cause it, and posible solutions? On Fri, 27 Apr 2007 10:44:28 GMT, Thor wrote: > Anyone have any ideas to what might cause it, and posible solutions? it can't find the hd, which patchlevel are you running? -- If you have already compiled drivers or have linux.2 please put them on Live BootCd and...

Image in image
Hi, I have a project where clients viewing my website can buy t-shirts. They can choose from a number of t-shirt colors and shapes which are their plain colour. They can also choose a number of prints to be placed on the t-shirt. These will be graphics stored in a database. My problem is on how I can displaty the t-shirt with the graphics or logo they chose on te t-shirt. It would be something like drawing text on an image but instead drawing an existing image on the base image. Any Ideas? (I am using visual studio 2005 and vb.NET)   RegardsMerovingian you 1. You can create a...

Imaging, but not imaging
We multicasted to 43 machines. Updated the image on the master. Multicasted the updated image to 36 machines. (the other 7 wouldn't join the session for some unknown reason). I visually verified that all 36 were imaging. One of the 8 which didn't rename appears to not even have been imaged. The problems with the previous image were still there. It's as though the machine didn't image even though I saw it take part in the session and the temp bar going across the screen. What the heck's going on here? AlaN As a try, what happens if you boot either to PXE ...

image and image
// create an image object, using the filename we just retrieved System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file)); // create the actual thumbnail imageSystem.Drawing.Image thumbnailImage = image.GetThumbnailImage(64, 64, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);   now my question is how to display this image in my image1 control in (version 1.1) the below line of code is not working.  Image1.ImageUrl=thumbnailImage.ToString();Mark As Answer If my reply helped you. Hi, you can save t...

Background image and web form size
Hi All! I've put a background image in my web form and I want the web form to be the same size as the image. But at the moment the background image keeps repeating itself! Is there anyway to set the web form to a fixed size based on the background image? I also have a datagrid that keeps expanding so am not sure how to deal when it becomes larger than the background image. Any help would be great, Thanks! Check out this page, it should help you to implement a background image: Jared - Livingston Family Website...

Image on Image
I am trying to display a page that has image of a map on it. The user can then place other images of red thumbtacks on the image at different locations. Then when these thumb tacks are clicked on, they open a folder of pics related to the area. I saw a method in the imageButton class that returns the (x,y) of the location where the user clicked. I thought I could use this information to place another, smaller image button, on that area. My problem is that i can't seem to get the bottom imageButton to be transparent so I can see the smaller one. Am i on the right track with this. Any advi...

Creating Thumbnail Images
Hi all, I have a script that uploads an image and creates a thumbnail for it. Ideally this thumbnail would be a smaller filesize but this is not what is happening. I have just uploaded a few images one of which was 378x521px and 11.3Kb. The thumbnail image created from this was 145x200 and 55.5Kb! Can anyone please tell me what I am doing wrong. I am using the GetThumbnailImage method as such:  System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero);myThumbnail.Save (Server.MapPath(sSavePath + sThumbFile)); Many thank...

DPI & Image size... How can I display an image with a high DPI as large on screen and have it print at its smaller Image size?
I was wondering if anyone could help with this.If I have an image I'm rendering through Bitmap.Save(Response.Outputstream,  ImageFormat.Jpeg)  it's 300 DPI with a WidthxHeight of ~3inch by ~2inch (~1000 X ~700 pixels), How can I display it on screen at its resolution but print it at its widthxheight. In photoshop the image is large on screen and correclty sized on the print out...when i render it in my web app its small on screen and correclty sized on the print out. Thanks.  I have found my problem :¬DPrinting via IE ignores the set resolution and just prints the ...

Web resources about - Get Image Size from New Image -

Twist Image
At Twist Image, we connect brands to people and people to brands. Let us show you what we mean.

Wikipedia:WikiProject Images and Media/Photography - Wikipedia, the free encyclopedia
This WikiProject 's primary aim is to encourage the contribution and improvement of photographs on Wikipedia. The project seeks to act as a focal ...

Flood of online support after Sonny Bill Williams tweets graphic images of dead children
Sonny Bill Williams has received a flood of online support for his decision to share two pictures of dead children on social media in an attempt ...

Sonny Bill Williams tweets graphic images of dead children after visiting Syrian refugee camps
Sonny Bill Williams has tweeted highly graphic images of two dead children after returning from Syrian refugee camps in Lebanon, demanding to ...

Ars’ favorite science images of 2015
... it's one thing to hear a description of the developing brain, and another thing entirely to see one as it's developing. In some cases, images ...

This New Year's Eve, make sure your PC is safely backed up with our O&O Disk Image 9 Downloadcrew Giveaway ...
... backup this New Year’s Eve? That’s right, today, December 31 we’re providing you with a 24-hour giveaway of the brilliant O&O DiskImage 9 Professional ...

First Images of Benedict Cumberbatch as Doctor Strange Released
... that Benedict Cumberbatch would play the title character, but Marvel is finally starting to unleash their own magic with a few production images. ...

Rochester row: Did new rail station drop an image of St John because it was 'too Christian'?
An image of St John was dropped at the design stage, leading to suggestions that it was not included because it would have offended multi-cultural ...

‘The Path’: First Images From Hulu’s Aaron Paul-Michelle Monaghan Drama
Hulu has released the first batch of still from The Path , its upcoming drama about a cult that stars Aaron Paul and Michelle Monaghan . Created ...

The Year In Photos:'s Most Compelling Images From 2015
Our staff photogs' top picks. Fast Company's photo team hit the streets this year in search of fresh, compelling stories about creative inspiration ...

Resources last updated: 1/1/2016 5:43:51 AM