FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DRAWING

Get the dimensions of a PICT resource before loading it in memory


Connaître les dimensions d'une Image PICT sans la charger en mémoire
I say:
Here let me take a try at this one. I was in a good mood today so decided it wouldn't be that hard to right up a routine that returned the hight and width of a PICT resource. Here is the function:

'================================
CLEAR LOCAL
  DIM rsrcHndl&, resErr%, h%, w%, rect.8
LOCAL FN pictRsrcRect(resID%, @pictHght&, @pictWdth&)
  CALL SETRESLOAD(_false)
  rsrcHndl& = FN GETRESOURCE(_"PICT",resID%)
  resErr% = FN RESERROR
  CALL SETRESLOAD(_pTrue)
  LONG IF resErr% = _noErr
    CALL READPARTIALRESOURCE(rsrcHndl&, 2, @rect, 8)
    resErr% = FN RESERROR
    LONG IF resErr%
      BEEP
    XELSE
      h% = rect.bottom% - rect.top%
      w% = rect.right% - rect.left%
      POKE WORD pictWdth&, w%
      POKE WORD pictHght&, h%
    END IF
  XELSE
    BEEP
  END IF
END FN
'================================

You would call it like this:

FN pictRsrcHW(resID%, hght%, wdth%)

resID% is the ID to a PICT resource, it's assumed that the resource is an a resource file that is already open, ie the main resource file specified with the RESOURCE statement

hght% is the variable where the height of the picture will be returned

wdth% is the variable where the width of the picture will be returned

So if you wrote this:

FN pictRsrcHW(128, hght%, wdth%)
PRINT hght%, wdth%

the height and width of picture 128 would be printed.

If you would like me to write a similar function for getting the height and width of a PICT file, I would be very willing to do so.

No problem. The code's below. I personaly like the other code better, it just looks nicer. A good way to test this out would be to use the following:

pictFileName$ = FILES$(_fOpen, "PICT", , vRefNum%)
FN pictFileHW(pictFileName$, vRefNum%, hght%, wdth%)
PRINT hght%, wdth%

That returns the height and width of the file that the user selected. This function works the same as the previous in that it returns the values in the hght% and wdth% variables.

BTW, could somebody remind me about how I would go about uploading this code to the web ring?

'================================
'call with: FN pictFileHW(pictFileName$, vRefNum%, hght%, wdth%)
'
'pictFileName$ - name of PICT file
'vRefNum% - volume reference number of file
'hght% - return height in this variable
'wdth% - return width in this variable
'================================
CLEAR LOCAL
  DIM h%, w%, fileRect.8
LOCAL FN pictFileHW(filename$, volRefNum%, @filePictHght&, @filePictWdth&)
  OPEN "ID",1,filename$,8,volRefNum% 'open files data fork for input
  RECORD 1, 64, 2 'set file position to that of the pict rect
  READ# 1, fileRect 'read the rect into the var fileRect
  CLOSE #1 'close the file
  h% = fileRect.bottom% - fileRect.top% 'calculate height
  w% = fileRect.right% - fileRect.left% 'calculate width
  POKE WORD filePictWdth&, w% 'put the width into the width var
  POKE WORD filePictHght&, h% 'put the width into the height var
END FN

Forrest Blanton