Home All Groups Group Topic Archive Search About
Author
16 Jan 2006 4:17 PM
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

Author
16 Jan 2006 4:31 PM
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
Author
16 Jan 2006 4:54 PM
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


"Jay Taplin" <jtap***@integraware.com> wrote in message
news:KTPyf.7590$Zo.1520@trnddc07...
Show quoteHide quote
> 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
>
Author
16 Jan 2006 4:43 PM
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
Author
16 Jan 2006 8:00 PM
Herfried K. Wagner [MVP]
"James T." <carr***@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/>