467,211 Members | 1,224 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,211 developers. It's quick & easy.

Image dimensions?

Hello!

I am using following code to get all JPEG files in a directory. Data,
including file name, length, creation date, etc will be stored in a
DataTable. Now I would like to add two extra colums to the DataTable -
height and width.

I was wondering, what is the fastest way to get the dimensions (height and
width) of image stored on server hd?

Dim Directory As New IO.DirectoryInfo(Path)
Dim File As IO.FileInfo
Dim Files As IO.FileInfo() = Directory.GetFiles("*.jpg")

Thanks!
James
Jan 16 '06 #1
  • viewed: 1872
Share:
4 Replies
You could try this:

Private Function GetJPEGSize(ByVal Filename As String, ByRef Width As
Integer, ByRef Height As Integer) As Boolean
Dim img As Image

Try
img = Image.FromFile(Filename)

Width = img.Width
Height = img.Height

Return True
Catch
Return False
End Try
End Function

You call this function by:

If GetJPEGSize("C:\scan0001.jpg", intWidth, intHeight) Then
System.Console.WriteLine("WIDTH: " & intWidth.ToString & " -
HEIGHT: " & intHeight.ToString)
End If

I hope this helps.

Jay Taplin, MCP
Jan 16 '06 #2
James,

To store it you need in my opinion the image object before you can make a
byteArray from it (blob).

In that image are the properties height and width

I hope this helps,

Cor
Jan 16 '06 #3
Jay, thank you for prompt reply!

I have already tried it and it seems that this approach is slowing down the
system... I have tested it with a directory containing about 60 image files.

Any alternatives?

James
"Jay Taplin" <jt*****@integraware.com> wrote in message
news:KTPyf.7590$Zo.1520@trnddc07...
You could try this:

Private Function GetJPEGSize(ByVal Filename As String, ByRef Width As
Integer, ByRef Height As Integer) As Boolean
Dim img As Image

Try
img = Image.FromFile(Filename)

Width = img.Width
Height = img.Height

Return True
Catch
Return False
End Try
End Function

You call this function by:

If GetJPEGSize("C:\scan0001.jpg", intWidth, intHeight) Then
System.Console.WriteLine("WIDTH: " & intWidth.ToString & " -
HEIGHT: " & intHeight.ToString)
End If

I hope this helps.

Jay Taplin, MCP

Jan 16 '06 #4
"James T." <ca*****@gmail.com> schrieb:
I am using following code to get all JPEG files in a directory. Data,
including file name, length, creation date, etc will be stored in a
DataTable. Now I would like to add two extra colums to the DataTable -
height and width.

I was wondering, what is the fastest way to get the dimensions (height and
width) of image stored on server hd?

Dim Directory As New IO.DirectoryInfo(Path)
Dim File As IO.FileInfo
Dim Files As IO.FileInfo() = Directory.GetFiles("*.jpg")


\\\
Using img As Image = Image.FromFile(...)
Height = img.Height
Width = img.Width
End Using
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dave | last post: by
8 posts views Thread by Abs | last post: by
14 posts views Thread by D. Alvarado | last post: by
6 posts views Thread by MurrayTh | last post: by
4 posts views Thread by chrisse_2@hotmail.com | last post: by
2 posts views Thread by Adam Teale | last post: by
6 posts views Thread by Samuel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.