Re: Compositing two NSImages
Re: Compositing two NSImages
- Subject: Re: Compositing two NSImages
- From: Brian Webster <email@hidden>
- Date: Sun, 24 Jun 2001 23:36:36 -0500
On Sunday, June 24, 2001, at 07:58 PM, cocoa-dev-
email@hidden wrote:
Hi. I have two 32x32 px NSImage's and I would like to get one above the
other in a new, third one (or, on top of one of the original
ones, since
I wont need the building blocks). How do I do this most easily...Do I
have to create multiple NSImageReps etc or is there a better way?
You can draw into an image the same way you draw into a view, by
first locking focus on the image and then performing draw
operations.
NSImage *image1, *image2, *destImage;
NSRect rect;
rect.origin = NSMakePoint(0, 0);
rect.size = [image1 size];
destImage = [[NSImage alloc] initWithSize:[image1 size]];
[destImage lockFocus];
[image1 compositeToPoint:NSMakePoint(0, 0) fromRect:rect
operation:NSCompositeSourceOver];
[image2 compositeToPoint:NSMakePoint(0, 0) fromRect:rect
operation:NSCompositeSourceOver];
[destImage unlockFocus];
--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster