PDA

Click to See Complete Forum and Search --> : How can I figure out the size of an image file without loading the image?


MrPolite
Dec 23rd, 2001, 01:51 PM
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)

Arbiter
Dec 23rd, 2001, 02:39 PM
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...

DaoK
Dec 23rd, 2001, 03:09 PM
MsgBox FileLen(("C:\iplist.txt")) / 1024 & " ko"

Arbiter
Dec 23rd, 2001, 03:47 PM
Doesn't tell you height and width of the image though Daok...

DaoK
Dec 23rd, 2001, 04:10 PM
oops sorry I just checked the Title :( my bad

DaoK
Dec 23rd, 2001, 04:13 PM
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 :


http://www.vbforums.com/attachment.php?s=&postid=713477

Sastraxi
Dec 23rd, 2001, 04:42 PM
Look for info on the Bitmap file header like Arbiter said. I believe there (maybe) is a control at VBAccelerator - http://www.vbaccelerator.com/.

MoMad
Dec 27th, 2001, 12:57 AM
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.

Arbiter
Dec 27th, 2001, 02:05 AM
I think that's what he's doing now, but its's too slow....

beachbum
Dec 27th, 2001, 02:06 AM
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
StuartPrivate Type GifHeader
ID As String * 3
Verision As String * 3
GifWidth As Integer
GifHeight As Integer
End Type
Dim MyGif As GifHeader

Private Sub Command1_Click()
LoadGif "C:\WINDOWS\DESKTOP\res0.gif"
End Sub

Public Sub LoadGif(Filename As String)
Open Filename For Binary As #1
Get #1, , MyGif
Close #1

With MyGif
Debug.Print .GifWidth
Debug.Print .GifHeight
End With
End Sub

oetje
Dec 27th, 2001, 08:43 PM
All the header informations for common file types are on http://www.wotsit.org/ :) It's really not hard to implement