|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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 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 > 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 "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/>
Display the contents of a folder in a listbox?
How do I extract a page from word and insert into a new word document using VB OFF TOPIC: Famous failed IT projects Webbrowser & XML ms.public.dotnet.vb.general - an "ex group" Append to XML? Enter key vs Return key Comm Ports Reading dll-Functions and execute them Question on VB.Net security for the application to run on network drive |
|||||||||||||||||||||||