Re: Painting into a NSImage / Combining two NSImage objects
Re: Painting into a NSImage / Combining two NSImage objects
- Subject: Re: Painting into a NSImage / Combining two NSImage objects
- From: "Alastair J.Houghton" <email@hidden>
- Date: Tue, 2 Sep 2003 16:36:13 +0100
On Tuesday, September 2, 2003, at 04:05 pm, Markus Hanauska wrote:
I have two NSImage objects, both are parts of my resource bundle.
I want to combine both two a third NSImage object, so that image1 is
overlayed by image2. How can I do that?
[snip]
It's such a simple task, two lines of code in Java, why can't it be
that simple as well in Cocoa?
It is.
You need to -lockFocus on the image you want to paint into, and
-unlockFocus when you've finished painting.
Something like
NSImage *newImage = [[NSImage alloc] initWithSize:NSMakeSize(width,
height)];
[newImage lockFocus];
[image1 compositeToPoint:NSMakePoint(x1,y1)
operation:NSCompositeSourceOver];
[image2 compositeToPoint:NSMakePoint(x2,y2)
operation:NSCompositeSourceOver];
[newImage unlockFocus];
should do the trick; obviously there are a lot of variations possible.
You might need to call the -setFlipped: method if you find your image
is the wrong way up.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.