Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to read image Width and Height in Pixel (Works in VB, ASP, VBScript)?
[ All Languages » VB »  Bitmap]

Total Hit ( 3466)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can use the following code to read image height and width in pixels.

If you want to use this code in ASP or VB Script then you have to compile the code in to DLL and then you can call CreateObject Method.

Steps if you are using in ASP/VBScript

- Create an ActiveX DLL project
- Rename the Project1 to MyTools
- Rename Class1 to CImage
- Add the following code to CImage class
- Compile the dll

Click here to copy the following block
Private Declare Function MulDiv Lib "kernel32" ( _
    ByVal Mul As Long, _
    ByVal Nom As Long, _
    ByVal Den As Long) As Long

'//Returns Image Width/Height In Pixel
Public Function GetImageProperties(ByVal sPath As String, ByRef retWidth, ByRef retHeight)
  Dim pic As IPictureDisp

  On Error GoTo errHandler
  Set pic = LoadPicture(sPath)

  retWidth = HM2Pix(pic.Width)
  retHeight = HM2Pix(pic.Height)
  'MsgBox "H=" & nHeight & " W=" & nWidth

  Set pic = Nothing
  Exit Function
errHandler:
  Err.Raise Err.Number, Err.Source, Err.Description
End Function

' HM2Pix
'
' Converts HIMETRIC to Pixel
'
Private Function HM2Pix(ByVal Value As Long) As Long
  HM2Pix = MulDiv(Value, 1440, 2540) / Screen.TwipsPerPixelX
End Function

Using in VB Application

Click here to copy the following block
'//Using in VB Application

Private Sub Command1_Click()
  Dim obj, nWidth, nHeight
  Set obj = CreateObject("MyTools.CImage")
  Call obj.GetImageProperties("C:\Inetpub\wwwroot\STS\images\products\spd_ashley.jpg", nWidth, nHeight)
  MsgBox "H=" & nHeight & " W=" & nWidth
End Sub

Using in ASP

Click here to copy the following block
<%

Dim obj, nWidth, nHeight
Set obj = Server.CreateObject("MyTools.CImage")
call obj.GetImageProperties("C:\Inetpub\wwwroot\STS\images\products\spd_ashley.jpg",

nWidth,nHeight)
Response.Write "H=" & nHeight & " W=" & nWidth

%>

Using in VB Script

Click here to copy the following block
Dim obj, nWidth, nHeight
Set obj = CreateObject("MyTools.CImage")
Call obj.GetImageProperties("C:\Inetpub\wwwroot\STS\images\products\spd_ashley.jpg", nWidth, nHeight)
MsgBox "H=" & nHeight & " W=" & nWidth



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.