小编Pat*_*ick的帖子

核心图形和GIF颜色表

我试图限制动画GIF(从数组创建CGImageRef)的颜色数量.

但是,我实际上很难设置自定义颜色表.有谁知道如何使用Core Graphics做到这一点?

我知道kCGImagePropertyGIFImageColorMap.下面是一些测试代码(从这个github gist中大量借用- 因为它是kCGImagePropertyGIFImageColorMapGoogle 唯一可以找到的实例).

NSString *path = [@"~/Desktop/test.png" stringByExpandingTildeInPath];

CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:path]);
CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);

const uint8_t colorTable[ 8 ] = { 0, 0, 0, 0, 255, 255, 255 , 255};
NSData* colorTableData = [ NSData dataWithBytes: colorTable length: 8 ];
NSMutableDictionary *gifProps = [NSMutableDictionary dictionary];

[gifProps setObject:colorTableData forKey:(NSString *)kCGImagePropertyGIFImageColorMap];
[gifProps setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImagePropertyGIFHasGlobalColorMap];

NSDictionary* imgProps = [ NSDictionary dictionaryWithObject: gifProps 
                                                      forKey: …
Run Code Online (Sandbox Code Playgroud)

macos cocoa core-graphics gif

7
推荐指数
1
解决办法
2147
查看次数

NSTableCellView中的NSButton:如何找到所需的objectValue?

我有一个基于视图的NSTableView,它通过绑定填充.我的textFields和imageViews绑定到NSTableCellView的objectValue属性.

如果我想在我的NSTableCellView中有一个编辑/信息按钮:

  1. 谁应该成为按钮动作的目标?

  2. 目标如何获得与按钮所在的单元格关联的objectValue?

我最终想要显示一个基于objectValue的popover/sheet.

cocoa nstableview cocoa-bindings nsbutton nstableviewcell

4
推荐指数
2
解决办法
4053
查看次数