相关疑难解决方法(0)

核心图形和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
查看次数

标签 统计

cocoa ×1

core-graphics ×1

gif ×1

macos ×1