PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How can I figure out the size of an image file without loading the image?-VBForums
Results 1 to 11 of 11

Thread: How can I figure out the size of an image file without loading the image?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Exclamation How can I figure out the size of an image file without loading the image?

    I'm writing a little thumbnail control and my problem is that it's super slow because it uses loadpicture(). I can use the LoadImage() API, but the other problem is that I have to know the original size of the image before I can use LoadImage().
    Is there any way to figure out the height and width of an image file without actually loading the whole thing? any API function to do that? or is it stored anywhere in the image file? ( I dont want to load the image compeletly because it will be the same speed as LoadPicture, my point is to figure out the size of the actuall image and do my calculations; then I would only load the image in a small size with LoadImage)

  2. #2
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Most image files contain a header which details the height/width of the image. If you find the header information of the file type you're trying to load, then you need merely load the first few bytes of the file to retrieve the header...
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  3. #3
    DaoK
    Guest
    VB Code:
    1. MsgBox FileLen(("C:\iplist.txt")) / 1024 & " ko"

  4. #4
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Doesn't tell you height and width of the image though Daok...
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  5. #5
    DaoK
    Guest
    oops sorry I just checked the Title my bad

  6. #6
    DaoK
    Guest
    You will need to get information like Windows does. Here a screenshot to prove you that you can do it without open anything because it is written in the file property :



  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Look for info on the Bitmap file header like Arbiter said. I believe there (maybe) is a control at VBAccelerator - http://www.vbaccelerator.com/.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    A Much Much simpler way...

    Put a picbox on the form and make it "autosize" AND set the mode to "Pixels", then load the picture into the form Then take the width and height of the picbox, this will work with bitblt and/or directX. Its the simplest method I know. Hope its helpful.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  9. #9
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    I think that's what he's doing now, but its's too slow....
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  10. #10
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi MrPolite
    I have found the header file information for GIF files but the promising looking links for jpg etc timed out... so here is something to get u started and to let u know that it can indeed be done.. all u need to know is the header structure for each type of file
    Regards
    Stuart
    VB Code:
    1. Private Type GifHeader
    2.     ID As String * 3
    3.     Verision As String * 3
    4.     GifWidth As Integer
    5.     GifHeight As Integer
    6. End Type
    7. Dim MyGif As GifHeader
    8.  
    9. Private Sub Command1_Click()
    10.     LoadGif "C:\WINDOWS\DESKTOP\res0.gif"
    11. End Sub
    12.  
    13. Public Sub LoadGif(Filename As String)
    14.     Open Filename For Binary As #1
    15.         Get #1, , MyGif
    16.     Close #1
    17.    
    18.     With MyGif
    19.         Debug.Print .GifWidth
    20.         Debug.Print .GifHeight
    21.     End With
    22. End Sub
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  11. #11
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    All the header informations for common file types are on http://www.wotsit.org/ It's really not hard to implement
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width