gpt4 book ai didi

objective-c - 如何在 OSX 10.9 (Mavericks) 的 NSWindow 上使用 CIFilter?

转载 作者:太空狗 更新时间:2023-10-30 03:24:30 26 4
gpt4 key购买 nike

由于某些原因,涉及使用私有(private) API CGSAddWindowFilter() 的旧技巧似乎不再适用于 Mavericks。我尝试了 How does on-screen color inversion work in OS X? 中描述的一些代码下面的代码导致以下 window .

#import "AppDelegate.h"

//Declarations to avoid compiler warnings (because of private APIs):
typedef void * CGSConnection;
typedef void * CGSWindowID;
extern OSStatus CGSNewConnection(const void **attributes, CGSConnection * id);
typedef void *CGSWindowFilterRef;
extern CGError CGSNewCIFilterByName(CGSConnection cid, CFStringRef filterName, CGSWindowFilterRef *outFilter);
extern CGError CGSAddWindowFilter(CGSConnection cid, CGSWindowID wid, CGSWindowFilterRef filter, int flags);
extern CGError CGSSetCIFilterValuesFromDictionary(CGSConnection cid, CGSWindowFilterRef filter, CFDictionaryRef filterValues);

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self.window setOpaque:NO];
[self.window setAlphaValue:1.0];
[self.window setBackgroundColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.1]];
self.window.level = NSDockWindowLevel;

CGSConnection thisConnection;
CGSWindowFilterRef compositingFilter;
int compositingType = 1; // under the window

/* Make a new connection to CoreGraphics */
CGSNewConnection(NULL, &thisConnection);

/* Create a CoreImage filter and set it up */
CGSNewCIFilterByName(thisConnection, CFSTR("CIColorInvert"), &compositingFilter);
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:3.0] forKey:@"inputRadius"];
CGSSetCIFilterValuesFromDictionary(thisConnection, compositingFilter, (__bridge CFDictionaryRef)options);

/* Now apply the filter to the window */
CGSAddWindowFilter(thisConnection, (CGSWindowID)[self.window windowNumber], compositingFilter, compositingType);
}

@end

有谁知道像在 OSX 10.8 中那样将滤镜应用于背景的技巧吗?

我需要这个才能制作 MenuBarFilter再次在 Mavericks 工作。

最佳答案

你去吧:

typedef void * CGSConnection;
extern OSStatus CGSSetWindowBackgroundBlurRadius(CGSConnection connection, NSInteger windowNumber, int radius);
extern CGSConnection CGSDefaultConnectionForThread();

- (void)enableBlurForWindow:(NSWindow *)window
{
[window setOpaque:NO];
window.backgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.5];

CGSConnection connection = CGSDefaultConnectionForThread();
CGSSetWindowBackgroundBlurRadius(connection, [window windowNumber], 20);
}

关于objective-c - 如何在 OSX 10.9 (Mavericks) 的 NSWindow 上使用 CIFilter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19575642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com