Hello,
Can I get the width, height and color depth of picture (bmp, jpg) using VB or API
thanks,
Belal
Printable View
Hello,
Can I get the width, height and color depth of picture (bmp, jpg) using VB or API
thanks,
Belal
Like this: :D
(Note that this function needs a 'frmMain' to work, replace this by your form's name..)
Code:'Declares
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Sub GetSize(iFileName As String, iW As Long, iH As Long)
Dim DC As Long
Dim Temp As IPictureDisp
'Create compatible DC
DC = CreateCompatibleDC(frmMain.hdc)
'Error: Can't create compatible DC
If DC < 1 Then: Exit Sub
'Load bitmap
Set Temp = LoadPicture(iFileName)
SelectObject DC, Temp
'Apply values
iW = frmMain.ScaleX(Temp.Width)
iH = frmMain.ScaleY(Temp.Height)
'Release memory
DeleteObject Temp
Set Temp = Nothing
End Sub
Use it like this:
Code:Dim W As Long
Dim H As Long
frmMain.ScaleMode = vbPixels
GetSize "C:\test.bmp", W, H
MsgBox "Size is " & W & "x" & H & " pixels."