[comp.sys.mac.programmer] Scrap Manager

dredick@vax.bbn.com (The Druid) (08/06/88)

I am writing a DA that reads a MacPaint Doc and displays it. Well, this
works fine and I like it. 

So..., I want to be able to cut pieces of the Bit Map frma my DA's window out
and save it in the Scrap Manager as a PICT. I plan to be able to
paste it anywhere I want.

But I have tried everything and I can't get it to work.

So..., How do you specified a Bit Map in a 'PICT'? or am I going about this
wrong?
===============================================================================
=    The Druid (dredick@bbn.com)                                              =
=                   "Did you ever feel that you were a typewriter,            =
=                    when everone else in the world was a wordprocessor"      =
===============================================================================

jkingdon@chinet.chi.il.us (James Kingdon) (08/07/88)

In article <28049@bbn.COM> dredick@vax.bbn.com (The Druid) writes:
>So..., How do you specified a Bit Map in a 'PICT'? or am I going about this
>wrong?

I would think you could just do an OpenPicture, then a CopyBits (giving
it as destination bitmap thePort^.portBits perhaps, I'm not sure the
destination bitmap even matters), then ClosePicture and so on.  Have
you tried this?

Disclaimer:  this is just based on reading Inside Mac, I haven't tried it.

imp@crayview.msi.umn.edu (Chuck Lukaszewski) (08/08/88)

In article <6229@chinet.chi.il.us>, jkingdon@chinet.chi.il.us (James Kingdon) writes:
> In article <28049@bbn.COM> dredick@vax.bbn.com (The Druid) writes:
> >So..., How do you specified a Bit Map in a 'PICT'? or am I going about this
> >wrong?
> 
> I would think you could just do an OpenPicture, then a CopyBits (giving
> it as destination bitmap thePort^.portBits perhaps, I'm not sure the
> destination bitmap even matters), then ClosePicture and so on.  Have
> you tried this?
>
That approach will disappoint you.  The _OpenPicture and _ClosePicture traps
are a sort of 'journaling' mechanism by which a series of quickdraw operations
can be recorded.  _OpenPicture operates on a rectangle you specify, not on
a brand new window.

The fastest way to get something into PICT format is to build the picture with
a bitmap editor like MacPaint, 'cut' it so it gets into the clipboard, and then
run ResEdit on the file you want to store the PICT in.  If the type 'PICT' does
not exist, then make it.  All you have to do now is do a 'paste' (Command-V).
ResEdit automatically converts the bitmap in the clipboard to a PICT.

That approach only works if you can make the bitmap before you complete your
program.  If you must do bitmap->PICT conversions on the fly in a program, you
will need to build your own PICT resource in memory.  This is pretty straight-
forward.  There is a technote which specifically covers this topic.  Basically,
the PICT format is as follows (I may not be exactly right, but this is close):

	1 word		-		length of resource data
	2 words		-		'PICT'
	4 words		-		rectangle
	1 word		-		rowbytes
	n words		-		bitmap data.

You will need to figure out the size of this structure before you make the
calls to turn it into a PICT, because you **MUST** use _NewHandle to allocate
the memory for it.  Once you have done that, you can either construct it in
the newly allocated block, or (if you have the bitmap already) you can just
use _BlockMove to copy it in.  Either way, the reason you need to use _NewHandle
is that you have to use Resource Manager calls to store the resource.  Since
your handle is not any previously existing resource, you can go straight to an
_AddResource call (assuming you have your resource file open).  Then do an
_UpdateResFile and you are set.

---===---===---===---===--/* Chuck Lukaszewski */--===---===---===---===---
ARPAnet/NSFnet/MRnet:      AppleLink:  SnailMail:              Ma Bell:
imp@crayview.msi.umn.edu   UG0138      Minneapolis MN 55418    612/789-0931

t-benw@microsoft.UUCP (Benjamin Waldmin) (08/09/88)

In article <6566@umn-cs.cs.umn.edu> imp@crayview.msi.umn.edu (Chuck Lukaszewski) writes:
>In article <6229@chinet.chi.il.us>, jkingdon@chinet.chi.il.us (James Kingdon) writes:
>> In article <28049@bbn.COM> dredick@vax.bbn.com (The Druid) writes:
>> >So..., How do you specified a Bit Map in a 'PICT'? or am I going about this
>> >wrong?
>> 
>> I would think you could just do an OpenPicture, then a CopyBits (giving
>> it as destination bitmap thePort^.portBits perhaps, I'm not sure the
>> destination bitmap even matters), then ClosePicture and so on.  Have
>> you tried this?
>>
>That approach will disappoint you.  The _OpenPicture and _ClosePicture traps
>are a sort of 'journaling' mechanism by which a series of quickdraw operations
>can be recorded.  _OpenPicture operates on a rectangle you specify, not on
>a brand new window.
>
>That approach only works if you can make the bitmap before you complete your
>program.  If you must do bitmap->PICT conversions on the fly in a program, you
>will need to build your own PICT resource in memory. 
[complicated stuff deleted]

No, you don't have to build your PICT resource.  There's a much easier way.
Suppose I have a window, and I want to create a PICT containing the windows
contents.  I can do the following:

	GetPort(&savePort);
	SetPort(&myWindow);
	myHandle = OpenPicture(myWindow.portRect);
	CopyBits(myWindow.portBits,mywindow.portBits,
		myWindow.portRect,myWindow.portRect,srcCopy,0L);
	ClosePicture();

This code opens a picture the same size as your window, and then does
a copybits, copying the window's contents onto itself.  However, since
a picture is open, drawing into the window with the CopyBits is recorded
in the picture.

Now that you have the picture, you can just copy it to a disk file or to
the clipboard.

Of course, if you only want to copy a portion of the window, rather than
the entire thing, make all the rectangles smaller!

Ben Waldman
Software Design Engineer
Microsoft Corporation

uw-beaver!microsoft!t-benw


Disclaimer:  My thoughts, opinions, suggestions and ideas are purely
my own and are not endorsed by my employer.