|
|
|
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
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)
Set pic = Nothing Exit Function errHandler: Err.Raise Err.Number, Err.Source, Err.Description End Function
Private Function HM2Pix(ByVal Value As Long) As Long HM2Pix = MulDiv(Value, 1440, 2540) / Screen.TwipsPerPixelX End Function |
Click here to copy the following block |
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 |
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
%> |
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 ) |
|
|