Results 1 to 10 of 10

Thread: How to read Dimension of .bmp file ??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Question How to read Dimension of .bmp file ??

    Hey guys...
    I have got a project which involves reading the dimensions (in pixels) of bitmap files.. i need to find the dim and then copy it to a template excel file..

    I am not able to find a way to get the dimensions.. please advice


    i am using Visual Studio 2005..


    cheers
    Abhilash

  2. #2
    Lively Member Xium's Avatar
    Join Date
    Jan 2007
    Posts
    78

    Re: How to read Dimension of .bmp file ??

    set picture box autosize = true and scalemode = 3 means pixels

    then simply after loading image in picture box u can use scale width and scale heghit for dim

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: How to read Dimension of .bmp file ??

    hey..

    thx for your reply..

    actually i donot need to view the picture... because i will be accepting a folder full of images and hav to read each of their dimensions and write onto excel. is there a way to just read the dimension in pixels off the .bmp file without opening it.


    thx
    Abhilash

  4. #4
    Lively Member Xium's Avatar
    Join Date
    Jan 2007
    Posts
    78

    Re: How to read Dimension of .bmp file ??

    just set visible = false and progamically load each image in picture and calculate its dimension and then load 2nd iimage and so on

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: How to read Dimension of .bmp file ??

    hey...
    thx for the info.. i understand wad u mean...

    but i am new to vb programming... can u please gimme the code for this function... i will be extremely grateful if u can help me out..

    i know how to accept the folder from the user and get the filenames (imagenames)... could you gimme the rest of the code.. ie. loading the image and calculating the dimensions and storing them in a variable...



    thx a lot
    abhilash

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: How to read Dimension of .bmp file ??

    If you don't want to load the picture into a picturebox, you can use the following code:

    vb Code:
    1. Option Explicit
    2. Private Type BITMAPFILEHEADER
    3.         bfType(1) As Byte
    4.         bfSize As Long
    5.         bfReserved1 As Integer
    6.         bfReserved2 As Integer
    7.         bfOffBits As Long
    8. End Type
    9. Private Type BITMAPINFOHEADER
    10.         biSize As Long
    11.         biWidth As Long
    12.         biHeight As Long
    13.         biPlanes As Integer
    14.         biBitCount As Integer
    15.         biCompression As Long
    16.         biSizeImage As Long
    17.         biXPelsPerMeter As Long
    18.         biYPelsPerMeter As Long
    19.         biClrUsed As Long
    20.         biClrImportant As Long
    21. End Type
    22. Private Sub GetBitmapSize(ByVal Bitmap As String, ByRef lWidth As Long, ByRef lHeight As Long)
    23. Dim hFile As Integer
    24. Dim bfh As BITMAPFILEHEADER
    25. Dim bih As BITMAPINFOHEADER
    26.     hFile = FreeFile
    27.     Open Bitmap For Binary Access Read Shared As #hFile
    28.     Get #hFile, , bfh
    29.     Get #hFile, , bih
    30.     Close #hFile
    31.     lWidth = bih.biWidth
    32.     lHeight = bih.biHeight
    33. End Sub
    34. Private Sub Command1_Click()
    35. Dim lngWidth As Long
    36. Dim lngHeight As Long
    37.     Call GetBitmapSize("c:\windows\zapotec.bmp", lngWidth, lngHeight)
    38.     MsgBox "Width: " & lngWidth & vbCrLf & "Height: " & lngHeight
    39. End Sub
    Last edited by Frans C; Mar 30th, 2007 at 03:23 AM.
    Frans

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to read Dimension of .bmp file ??

    Please do not make duplicate threads.

    Original thread in VB.NET forum:
    http://vbforums.com/showthread.php?t=460571
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: How to read Dimension of .bmp file ??

    Hey Frans

    thx a lot for your help


    cheers
    Abhilash

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: How to read Dimension of .bmp file ??

    Hey Frans!!

    looks like you gave me a code for VB 6.. i am using VB 2005.. sori to bother you but this code doesnt seem to work on vb 2005... please help..


    thx
    abhilash

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to read Dimension of .bmp file ??

    This is exactly why you should not make multiple threads in different forums.

    For the rest of the replies on the topic please see the vb.net thread of his I linked to in post #7.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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