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

Re: CALayer not displaying masked CGImage properly


  • Subject: Re: CALayer not displaying masked CGImage properly
  • From: Rob Boellaard <email@hidden>
  • Date: Fri, 9 Jan 2009 12:28:12 +0100



  Hi,

I took a .png image with alpha channel that I found on the web, loaded it as an CGImageRef in my app, and then passed it to both the normal NSView and the layer-backed view. This one gets displayed as I expected in both cases, ie. I see the View's background colour through the transparant area of the image.
This would mean I am not creating my own masked image correctly. I guess I am unclear about how an image mask should work with alpha channel. I'll experiment some more.


 thanks anyway,

 Rob


On Jan 8, 2009, at 9:56 AM, Rob Boellaard wrote:

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

_______________________________________________

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


References: 
 >CALayer not displaying masked CGImage properly (From: Rob Boellaard <email@hidden>)

  • Prev by Date: Problem with setting fonts in NSTextView
  • Next by Date: Re: Problem with setting fonts in NSTextView
  • Previous by thread: CALayer not displaying masked CGImage properly
  • Next by thread: Hyperlinks
  • Index(es):
    • Date
    • Thread