JPG Object Exposes Itself? (Access 97)

Hi All,
I did not see this question asked before: Do any of you know a way to determine whether a linked OLE type graphic (JPG) object can be made to tell you whether it is portrait or landscape orientation? I'd like to have a picture appear on a Form in, say, one of two Bound OLE fields, (or maybe even vary the field dimensions under VBA control!) as either portrait-oriented or landscape-oriented, but I need a way to let the VBA program determine the the picture orientation (or dimensions or something) beforehand.
Thanks! (PS: This board is a *great* source of info!) -dBETTSXX

Re: JPG Object Exposes Itself? (Access 97)

No answers were forthcoming, so I heaved a sigh and dug into the .JPG file structure. To save any of you (that might be inclined) the trouble, here is some VBA code that allows you to look into a .JPG file and determine it's orientation:

Dim ByteStr As String
Dim Ydim, Xdim As Integer

' Open the file for "input"
Open Cathnamefilename.JPG For Input As #1
Do While True
ByteStr = Input(1, #1)
' Search for an FFh (255d) byte, followed by a C0h (192d) byte (marker for file size block).
If Asc(CVar(ByteStr)) = 255 Then
ByteStr = Input(1, #1)
If Asc(CVar(ByteStr)) = 192 Then
' Throw away next two bytes after the FF C0 block marker.
ByteStr = Input(2, #1)
' Get the next four bytes. They contain the image dimensions in pixels.
ByteStr = Input(4, #1)
Exit Do
End If
End If
Loop
Close #1
' The first two of the four pixel bytes contain the "Y" (vertical) dimension.
Ydim = Asc(CVar(Mid(ByteStr, 1, 1))) * 256 + Asc(CVar(Mid(ByteStr, 2, 1)))
' The second two of the four pixel bytes contain the "X" (horizontal) dimension.
Xdim = Asc(CVar(Mid(ByteStr, 3, 1))) * 256 + Asc(CVar(Mid(ByteStr, 4, 1)))

' Lastly, compare the y-dimension to the x-dimension...
If Ydim > Xdim Then
' set OLE picture field (in ACESS form) to portrait orientation
' Picture dimensions are set in "twips", see Access Help for definition
olePicture.Width = 2665
olePicture.Height = 3073
Else
' set OLE picture field (in ACESS form) to landscape orientation
olePicture_1.Width = 3073
olePicture_1.Height = 2665
End If

Re: JPG Object Exposes Itself? (Access 97)

I think the JPG file format is fairly parameterized, that is to say what's in the file is identified by a series of block headers telling you what's coming. Here's some code that will accept a couple of other kinds of size blocks, and skip over blocks it doesn't recognize. I think it's a little more robust than what's above, but I wrote it a while ago.

Regards,
Jordan

Sub JPEGSize(JPEGfile As FileName, x As Integer, y As Integer)
' following code is a total rip-off of the PERL form # Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995
' modified slightly by alex@ed.ac.uk, rewritten in VB by jordan@gurus.com
x = -1: y = -1
Dim f As Integer: f = FreeFile
Open JPEGfile.FullPath For Binary As #f

Dim c1 As String, c2 As String, l As String, discard As String, xh As String, xl As String, yh As String, yl As String
Dim bc As Long
Dim bl As Integer