How to retrieve image size?

L

Leszek

Hello,

I need to set dynamically height and width attributes of an image control on
a WebForm. I know how to read the whole image from the hard-drive and use
its height and width properties. I guess it is not efficient as the whole
image needs to be read. I need to retrieve only two parameters: height and
width.

Is it possible to read only the size of image from the hard-drive?

Thanks,
Leszek Taratuta
 
A

Alex Papadimoulis

Leszek,

You would need to write a component that read the header of the image file.
If your dealing with large files, many requests, and not a huge server, it
may be something worthwhile doing.

OTOH, the client's machine will automatically size the image once
downloaded, and there isn't a huge overhead in determinging h/w of an image.

Alex Papadimoulis
 
L

Leszek

Alex:

What I am trying to accomplish is to resize the browser window to fit an
image. I need to retrieve the image size on the server side, so I could
generate a JavaScript code (window.open ...) providing proper width and
height of the window.
Is it difficult to write a code for reading just the image header?
I would need such code for .jpg, .gif, and .bmp.

Thanks,
Leszek Taratuta
 
J

Jaxon

you'll need to find a copy of the file format spec, then read the files
header and parse the info.

I did this a long time ago using VB6 and Gif images.


Greg Jackson
PDX, Oregon
 
L

Leszek

I have such functions in VBScript and classic ASP. I just thought there
would be a standard method somewhere using .NET.

Thanks,
Leszek
 
J

Jacob Yang [MSFT]

Hi Leszek,

Firstly I want to thank Alex and Greg for their great help in this issue. I
agree with them that we need to write our own functions to do what you need
in .NET.

On the other hand, you can send your feedback of our products to Microsoft
directly.

Contact Microsoft
http://register.microsoft.com/mswish/suggestion.asp
"...
Microsoft Wish

Make a product suggestion or feature request. Product enhancement
suggestions can include:
Improvements on existing products
Suggestions for additional features
Ways to make our products easier to use
..."

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
L

Lloyd Sheen

Where do you want to do this? Client or Server. If server then you can use
the .net classes to get the information. Check out the graphic classes.
Don't have access to the doc right now but I have done this. It is simple ,
just create the correct class (the hard part) , one of the constructors
takes the filename as input. Then there are readable properties to find out
most of the details of the image.
 
W

William LaMartin

Here is the way I would do it in VB.Net. I am not sure if this is what you
mean by reading the whole file or not.

Dim MyBitmap As New Bitmap(Server.MapPath(".") & "\MyPicture.jpg")
Me.Label1.Text = "The height is " & MyBitmap.Height.ToString & " and the
width is " & MyBitmap.Width.ToString
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top