billf@hpcvlx.cv.hp.com (Bill F. Faus) (03/10/90)
I need help on understanding how bit maps are put onto the screen.
Can someone give me a mimimal program that illustrates how a bit map
(say a simple rectangle 2 bytes wide and 100 bytes tall) is put onto
screen. I've read the QuickDraw chapter of "Inside MacIntosh",
but canot find a complete example that shows how to open a port,
build a bit map, and then display the bitmap onto the screen.
Which command actually writes to the screen? Is it SetPortBits,
or is it CopyBits? Can bitmaps be displayed without the use
of windows?
So far I've been fooling with the following Think C program,
which refuses to put anything on the screen:
main()
{
BitMap myBlob;
GrafPort myPort;
char Blob[200];
InitGraf(&thePort);
OpenPort(&myPort);
SetPort(&myPort);
myBlob.baseAddr = Blob;
myBlob.rowBytes = 2;
SetRect(&myBlob.bounds, 100, 100, 200, 102);
for (i = 0; i < 200; i++)
Blob[i] = 0x0F;
CopyBits(&myBlob, &myPort.portBits, &myBlob.bounds, &myPort.portRect,
srcCopy, 0L);
}
Any help would be appreciated. Or pointers to reference material.
-------------------------------
Bill Faus
HP Calculator Learning Products
billf@cv.hp.com
brecher@well.sf.ca.us (Steve Brecher) (03/12/90)
In article <101780003@hpcvlx.cv.hp.com>, billf@hpcvlx.cv.hp.com (Bill F. Faus) writes: > Can someone give me a mimimal program that illustrates how a bit map > (say a simple rectangle 2 bytes wide and 100 bytes tall) is put onto > screen... > > Which command actually writes to the screen? Is it SetPortBits, or is > it CopyBits? Can bitmaps be displayed without the use of windows? > > char Blob[200]; > ... > SetRect(&myBlob.bounds, 100, 100, 200, 102); You're on the right track. CopyBits can write to the screen, if the destination BitMap (or PixMap -- IM vol. V) coincides with (part of) the screen. SetPortBits just alters the current grafPort data structure; it does not draw. BitMaps can displayed without the use of windows, but you almost never would do that in a real application since the area outside of your windows is "owned" by system software. For your experiments, though, you can draw wherever you want! You want to think in terms of pixels, not bytes. The rectangle you want is 16 pixels wide and 100 pixels tall. Also note that the coordinate arguments to SetRect (L,T,R,B) are not in the same order as the fields of a Rect (T,L,B,R). Hence, your SetRect should be SetRect(&myBlob.bounds, 100, 100, 116, 200); > CopyBits(&myBlob, &myPort.portBits, &myBlob.bounds, &myPort.portRect, > srcCopy, 0L); Given the change to SetRect, this will draw on the screen. But, since CopyBits scales the drawing to fit the destination rectangle, it will draw a much larger area than you intend. To draw a 16x100 rectangle, you will need to change the dstRect argument to such a rectangle, e.g., by making it the same as the srcRect argument. -- brecher@well.sf.ca.us (Steve Brecher)