2012-02-09 5 views
2

contentViewとしてレイヤーを使用する方法はありますか?NSViewあらゆる種類のトリックを試しましたが、私が得るのは透明な領域だけです。別のルートに行き、CALayerの画像を取得して[NSApp setApplicationIconImage:]に使用してみましたが、不運なことはありません - ここでの問題は、オフスクリーンの画像の画像表現を作成することだと思います。いつものようにレイヤーバックNSViewをNSDockTile contentViewとして使用する

答えて

2

、私は私の答えはすぐに質問を投稿した後に:)私は今後の参考のためにそれをここに投稿しますしまった:私はココアで説明したように層のうちNSImageを作成することによって、それを解決することは、ここhttp://www.cimgf.com/2009/02/03/record-your-core-animation-animation/

私のガールフレンドのブログ記事であります

唯一欠けている部分がレンダリングされた何かを持っているために、ビューはとてもポストからのサンプルコードを使用して、ウィンドウに追加されなければならないということで、私の解決策は次のとおりです。

NSView *myView = ... 
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(-1000.0, -1000.0, 256.0, 256.0) styleMask:0 backing:NSBackingStoreNonretained defer:NO]; 
[window setContentView:myView]; 

NSUInteger pixelsHigh = myView.bounds.size.height; 
NSUInteger pixelsWide = myView.bounds.size.width; 
NSUInteger bitmapBytesPerRow = pixelsWide * 4; 
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 
CGContextRef context = CGBitmapContextCreate(NULL, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); 
CGColorSpaceRelease(colorSpace); 

[myView.layer.presentationLayer renderInContext:context]; 
CGImageRef image = CGBitmapContextCreateImage(context); 
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image]; 
CFRelease(image); 

NSImage *img = [[NSImage alloc] initWithData:[bitmap TIFFRepresentation]]; 
[NSApp setApplicationIconImage:img]; 
関連する問題