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

Make a bitmap picture


I make bitmapped images like this. Instead of using the PICTURE ON, PICTURE OFF on the quickdraw commands, make two gWorlds. Draw your picture in one of them. Then use the PICTURE ON, PICTURE OFF commands around a COPYBITS command. You then will have a handle to a bitmapped pict.

PICTURE ON
FN copyBits(World1&,World2&,rect.top%,rect.top%,0)
CALL FRAMERECT(rect)
PICTURE OFF ,pictHndl&

If you have a picture drawn on the screen and want to capture it to a pict handle use this command (the rect is the area of the current window you want to capture)

pictHndl& = USR GETPICT(rect) 'get the handle

You can then save the handle as a pict file with the following fn:

'=================
CLEAR LOCAL MODE 'saves picture handle PICT file
  DIM buff%(512)
LOCAL FN savePICTfile(pictHandle&,filename$,saVvolRefNum%)'saves PICT as a file
  LONG IF pictHandle& 'valid handle?
    DEF OPEN "PICT"
    OPEN "O",1,filename$,,volRefNum%
    WRITE FILE#1, @buff%(0),512 'save 512 byte empty header
    bytes& = FN GETHANDLESIZE(pictHandle&) 'get picture size
    WRITE FILE#1, [pictHandle&], bytes& 'save it
    CLOSE #1 'close it
  END IF
END FN
'----------------

You can also save it as a pict resource. This saves a pict as resource 4002 in your porgram's resource fork.

curResNum=FN CURRESFILE
appVol%=SYSTEM(_aplVol)
CALL USERESFILE(appVol%)
id@02
resName$=""
FN pGreplaceRes(pictHndl&,_"PICT",id,resName$)

Joe Lertola


If your goal is just to get the picture to a PICT file or to the clipboard, then you don't need to "flatten" it. PICT files and clipboard pictures have exactly the same internal format as the data you saved in your PICTURE ON...PICTURE OFF handle (except that a PICT file additionally has a 512-byte "dummy" header which is usually just filled with zeros). That is, a PICT file is (except for the 512-byte header) just a list of Quickdraw commands, and a clipboard picture is likewise.
If you dig inside a PICT file or a clipboard picture that contains a "bitmap," you'll actually find something like a "PackBitsRect" QuickDraw opCode, which takes as one of its parameters a (slightly compressed) pixmap.

So you _can_ save the picture just opening a file as type "PICT", writing 512 zeros to it, and then follow that by writing the contents of your PICTURE ON...PICTURE OFF handle. Similarly, you can use that same handle with PUTSCRAP to put the picture onto the clipboard.

Now, you may _want_ the picture to be in flattened "bitmap" (i.e., "PackBitsRect") format. The advantage of this is that it _might_ draw faster, depending on how complex the drawing is. The disadvantages are that it's likely to be larger than the equivalent "unflattened" file, and things like text and circles will likely have 72 dpi "jaggies" when you print the picture (while the "unflattened" version won't have that problem).

A "flattened" picture is created by recording a COPYBITS command. If you can display the whole picture on the screen at once, then you can use USR GETPICT to create such a picture for you. If your screen's not big enough (or you simply don't choose to display the picture), then you'd need to do something like this:

Create two (sufficiently large) offscreen GWorlds
SetGWorld to GWorld #1
Draw the picture
SetGWorld to GWorld #2
PICTURE ON
COPYBITS from GWorld #1 to GWorld #2
PICTURE OFF, pictHandle&
SetGWorld back to your monitor.
Dispose of GWorld #1 and GWorld #2

(Actually, this _might_ work with just a single offscreen GWorld, if you do the COPYBITS "from" the GWorld "to" itself--but I vaguely recall running into problems with that. (Don't take my word for it: experiment!))

After you do the above, pictHandle& will contain a "flattened" version of what you drew.

Rick