• 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
CALayer not displaying masked CGImage properly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CALayer not displaying masked CGImage properly


  • Subject: CALayer not displaying masked CGImage properly
  • From: Rob Boellaard <email@hidden>
  • Date: Thu, 8 Jan 2009 09:56:09 +0100

Hi everybody,

I am trying to learn CoreGraphics and CoreAnimation, things were going well, but now I seem to be stuck.

I have an image mask (CGImageRef) that displays nicely when I draw it directly in an NSView. But when I add the same image mask to a CALayer which I then add to a the super layer of a layer-backed NSView, the area that is supposed to be transparant is coloured black, no tranparancy there. Also the lines of the masked area are more jagged than when I draw it directly into an NSViews graphics context.

  here's the code from the "normal" NSView:

- (void)setImageRef:(CGImageRef)ref {
	CGImageRelease(imageRef);
	CGImageRetain(ref);

	imageRef = ref;
}

- (void)drawRect:(NSRect)rect {
CGRect viewRect = [CGAStructUtil convertNSRect:rect];

[[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];
CGContextRef cxt = [[NSGraphicsContext currentContext] graphicsPort];

//CGContextSetShouldAntialias(cxt, YES);

CGContextSetRGBFillColor(cxt, 0.1, 1.0, 0.1, 1.0); //green
CGContextFillRect(cxt, viewRect);

CGContextDrawImage(cxt, viewRect, imageRef);
}



the setImageRef is called by the Controller during awakeFromNib.

  here's the code from the layer-backed view:


- (void)setImageRef:(CGImageRef)ref { [self setWantsLayer:YES]; CALayer *rootLayer = self.layer; rootLayer.frame = [CGAStructUtil convertNSRect:[self frame]]; CALayer *contentLayer = [CALayer layer]; contentLayer.contents = (id)ref; contentLayer.frame = CGRectMake(0, 0, 100, 130); //contentLayer.opaque = NO; [rootLayer addSublayer:contentLayer]; }

If you need to see more code, like how I create the mask or something, please let me know.

thanks a lot,

  Rob

ps: I hoped the opaque property of CALayer would make a difference, but it doesn't.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CALayer not displaying masked CGImage properly
      • From: Rob Boellaard <email@hidden>
  • Prev by Date: Re: Large Core Data memory allocations for small rows
  • Next by Date: Re: Dock menu item action isn't performed in modal state
  • Previous by thread: Contract Job Opening
  • Next by thread: Re: CALayer not displaying masked CGImage properly
  • Index(es):
    • Date
    • Thread