• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Painting into a NSImage / Combining two NSImage objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

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

  • Prev by Date: Painting into a NSImage / Combining two NSImage objects
  • Next by Date: Breakpointing for kCGErrorIllegalArgument errors?
  • Previous by thread: Painting into a NSImage / Combining two NSImage objects
  • Next by thread: Re: Painting into a NSImage / Combining two NSImage objects
  • Index(es):
    • Date
    • Thread