CALayer not displaying masked CGImage properly
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