Question How to find the image size in Kb?

saichong

Member
Joined
Nov 21, 2009
Messages
10
Programming Experience
Beginner
hi all

i want to know how to find the image size in kb if the image is from a web site?

is that possible without loading it??
 
You can look at the ContentLength property which will be in bytes. Dividing by 1024 will get you the kb value you're looking for.

Here's an example using the logo from the boards here.

VB.NET:
		Dim req As HttpWebRequest = CType(WebRequest.Create("http://www.vbdotnetforums.com/images/vbdn/MainLogo.gif"), HttpWebRequest)
		req.Credentials = CredentialCache.DefaultCredentials
		Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
		Dim imgSize As Int64 = resp.ContentLength
		MessageBox.Show((imgSize / 1024).ToString())
 
Error 1 Type 'HttpWebRequest' is not defined.
Error 2 Name 'CredentialCache' is not declared.
Error 3 Type 'HttpWebResponse' is not defined.
 
MattP
Thank you very much

but i have a small problem
i want to load the image using picturebox

but if the form is minimized, then the image will not be loaded till the form window state become normal
so how can the image be loaded even if the form is minimized,
i am using
VB.NET:
picturebox1.ImageLocation = ("http://http.cdnlayer.com/dreamincode/home/images/peopleicon.png")
 
Back
Top