Results 1 to 2 of 2

Thread: Image Properties

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Egypt
    Posts
    179

    Image Properties

    Hello,

    Can I get the width, height and color depth of picture (bmp, jpg) using VB or API

    thanks,
    Belal

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Like this:
    (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."
    Last edited by Fox; Jun 15th, 2001 at 06:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width