Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Painting into a NSImage / Combining two NSImage objects



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.

References: 
 >Painting into a NSImage / Combining two NSImage objects (From: Markus Hanauska <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.