gpt4 book ai didi

cocoa - 使用 OS X NSColorspace 切换颜色同步配置文件

转载 作者:行者123 更新时间:2023-12-03 16:21:56 26 4
gpt4 key购买 nike

当我尝试在 NSWindow 对象上调用 setColorSpace 时,颜色没有变化。我的印象是我可以动态改变颜色的渲染方式。

这是我的 Controller 的 .h 文件

#import <Cocoa/Cocoa.h>

@interface MainWindow : NSWindowController <NSTextFieldDelegate>
{

}
@property (strong) IBOutlet NSWindow *theWindow;
@property (weak) IBOutlet NSTextField *RedField;
@property (weak) IBOutlet NSTextField *GreenField;
@property (weak) IBOutlet NSTextField *BlueField;
@property (weak) IBOutlet NSTextField *PatternField;
@property (weak) IBOutlet NSButton *ICCBox;
- (IBAction)UpdateICC:(id)sender;

@end

这是我的 Controller 的 .m 文件

#import "MainWindow.h"
#import <AppKit/AppKit.h>

@interface MainWindow ()

@end

@implementation MainWindow


- (id)init
{
self = [super init];

return self;
}

- (void)awakeFromNib
{
[_RedField setDelegate:self];
[_GreenField setDelegate:self];
[_BlueField setDelegate:self];
}


-(void) controlTextDidChange:(NSNotification *) note {

float redByte = [_RedField floatValue];
float redF = redByte/255.0;

float greenByte = [_GreenField floatValue];
float greenF = greenByte/255.0;

float blueByte = [_BlueField floatValue];
float blueF = blueByte/255.0;

_PatternField.backgroundColor = [NSColor colorWithCalibratedRed:redF green:greenF blue:blueF alpha:1];
}

- (IBAction)UpdateICC:(id)sender {

NSColorSpace *acs = [NSColorSpace adobeRGB1998ColorSpace];
NSColorSpace *scs = [NSColorSpace sRGBColorSpace];
NSColorSpace *dcs = [NSColorSpace deviceRGBColorSpace];

if(_ICCBox.state == NSOnState)
{
[_theWindow setColorSpace:scs];
}
else
{
[_theWindow setColorSpace:dcs];
}

}
@end

知道为什么这不起作用吗?

最佳答案

您应该将指定的通知发布到默认通知中心以立即应用更改(导致使用新的颜色配置文件重绘窗口)。

- (IBAction)UpdateICC:(id)sender {

NSColorSpace *acs = [NSColorSpace adobeRGB1998ColorSpace];
NSColorSpace *scs = [NSColorSpace sRGBColorSpace];
NSColorSpace *dcs = [NSColorSpace deviceRGBColorSpace];

if(_ICCBox.state == NSOnState)
{
[_theWindow setColorSpace:scs];
}
else
{
[_theWindow setColorSpace:dcs];
}

[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification object:_theWindow];
// In some cases additional call needed:
[_theWindow.contentView viewDidChangeBackingProperties];
}

关于cocoa - 使用 OS X NSColorspace 切换颜色同步配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207130/

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