
jpg file dimension retrieval
Hi everyone, I have a big problem I would like help with.
Here is the deal, I am having to retrieve jpg images from a MS-SQL
Server in the image data type. I will be displaying these images on
the web, but I need to scaled them down. So I need to get the
dimension of the picture from it. I have a couple peices of code that
i have tried but i always get the wrong thing. I'm going to post the
pieces i think are buggy and if anyone can see anything wrong, please
let me know. My suspicions are that I am looking for the wrong marker
within the jpg file.
I am displaying the image just fine, but when looking for the
dimensions, I get h=-1 w=-1 for the first segment of code, and h=55554
w=255 for the second.
Here is the first:
lngPos = 1
ExitLoop = false
do while ExitLoop = False and lngPos < mLngSize
do while AscB(midb(mStrBinaryData, lngPos, 1)) = 255 and lngPos <
mLngSize
lngPos = lngPos + 1
loop
if AscB(midb(mStrBinaryData, lngPos, 1)) < 192 or
AscB(midb(mStrBinaryData, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(mStrBinaryData, lngPos + 1,
2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
'
if ExitLoop = False then
mLngWidth = -1
mLngHeight = -1
'Depth = -1
else
mLngHeight = lngConvert2(midb(mStrBinaryData, lngPos + 4, 2))
mLngWidth = lngConvert2(midb(mStrBinaryData, lngPos + 6, 2))
'Depth = 2 ^ (asc(mid(mStrBinaryData, lngPos + 8, 1)) * 8)
'gfxSpex = True
end if
_______________________
Here is the second:
' Prefix found before image dimensions
lBinPrefix = ChrB(&h00) & ChrB(&h11) & ChrB(&h08)
' Find the last prefix (so we don't confuse it with data)
lLngStart = 1
Do
If InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3 = 3 Then Exit Do
lLngStart = InStrB(lLngStart, mStrBinaryData, lBinPrefix) + 3
Loop
' If a prefix was found
If Not lLngStart = 1 Then
mLngWidth = CLng("&h" & HexAt(lngStart+2) & HexAt(lngStart+3))
mLngHeight = CLng("&h" & HexAt(lngStart) & HexAt(lngStart+1))
End If