Image dimensions?

J

James T.

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
 
J

Jay Taplin

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
 
C

Cor Ligthert [MVP]

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
 
J

James T.

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
 
H

Herfried K. Wagner [MVP]

James T. said:
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
///
 

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

Top