我試圖將NSImage轉換成1.8的伽馬值,我沒有太大的運氣。我發現了一些代碼,但沒有任何工作。我有一個方法返回一個NSImage類別的NSBitmapImageRep。將1.8的Gamma應用到NSImage中
首先,我試着用CGColorSpaceCreateCalibratedRGB功能我在網上找到改變顏色空間,但是這並沒有影響:
- (NSBitmapImageRep *)OnePointEightBitmapImageRep{
CGColorSpaceRef colorSpace = CGColorSpaceCreateCalibratedRGB(
(CGFloat[3]){0.9505, 1.0000, 1.0891},//white point
(CGFloat[3]){0.0000, 0.0000, 0.0000},//black point
(CGFloat[3]){1.8010, 1.8010, 1.8010},//gamma rgb
(CGFloat[9]){0.4543, 0.2426, 0.0148, 0.3533, 0.6744, 0.0904, 0.1566, 0.0834, 0.7195} //rgb tristimulus
);
CGImageRef imageRef = CGImageCreateCopyWithColorSpace([self CGImage], colorSpace);
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:imageRef];
CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef);
return bitmap;
}
- (CGImageRef)CGImage{
return [self CGImageForProposedRect:nil context:nil hints:nil];
}
接下來,我嘗試設置的位圖圖像屬性中的伽瑪:
- (NSBitmapImageRep *)OnePointEightBitmapImageRep{
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:[self CGImage]];
NSLog(@"gamma: %@", [bitmap valueForProperty:NSImageGamma]);
[bitmap setProperty:NSImageGamma withValue:[NSNumber numberWithDouble:1.8f]];
NSLog(@"gamma: %@", [bitmap valueForProperty:NSImageGamma]);
return bitmap;
}
這設置屬性,但對輸出圖像沒有影響。
有沒有辦法做到這一點?
你是如何輸出圖像? –
像這樣: 'NSData * data = [bitmap representationUsingType:NSPNGFileType properties:nil]; [data writeToFile:@「 /image.png」atomically:YES];' –
keegan3d