레이어 NSView
을 의 contentView
으로 사용하는 방법이 있습니까? 모든 종류의 트릭을 시도했지만, 내가 얻는 것은 투명한 영역입니다. 또한 다른 경로로 이동하여 CALayer
에서 이미지를 가져 와서 [NSApp setApplicationIconImage:]
에 사용했지만 운이 좋지는 않습니다. 여기에서 문제는 오프 스크린 이미지의 이미지 표현을 만드는 것이라고 생각합니다. 평소처럼NSDockTile contentView로 레이어 백업 NSView 사용
2
A
답변
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];
:
유일한없는 조각은 내 솔루션은 아무것도 렌더링을하기 위해, 뷰 그래서 포스트에서 예제 코드를 사용하여 윈도우에 추가해야한다는 것입니다