Core animation image not drawn

Discussion in 'Mac Programming' started by ramy1989, Dec 2, 2012.

  1. ramy1989 macrumors newbie

    Nov 7, 2012
    I have opened a similar question on SO but no one answered yet.
    I have a CALayer and I'm trying to draw an image inside it:

    NSBundle* mainBundle= [NSBundle mainBundle];
    NSString* imagePath= [mainBundle pathForImageResource: @"shark.jpeg"];
    NSImage* sharkImage= [[NSImage alloc]initWithContentsOfFile: imagePath];
    CALayer* layer=[[CALayer alloc]init];
    layer.anchorPoint= CGPointZero;
    layer.position= CGPointMake(200, 150);
    layer.backgroundColor= CGColorGetConstantColor(kCGColorWhite);
    layer.borderColor= CGColorGetConstantColor(kCGColorBlack);
    view.wantsLayer= YES;
    [sharkImage drawInRect: layer.bounds fromRect: NSZeroRect operation: NSCompositeCopy fraction: 1.0];
    [CATransaction begin];
    [view.layer addSublayer: layer];
    [CATransaction commit];
    The image is loaded succesfully and I know this through debugging.
    But nothing is shown in the layer, why?

Share This Page