ドキュメントには、CGBitMapContextCreate はインデックス付きの色空間をサポートしていないと書かれていることは知っています。それは私にとって厄介です。表示する必要がある 256 ビットの PNG ファイルがたくさんあります。これらはすべてインデックス付きの色空間です。
<CGColorSpace 0x101301000> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)
CGImageRef をサポートされている色空間に変換して、これを機能させるにはどうすればよいですか?
問題が発生している私の方法は次のとおりです。
- (BOOL) renderToBuffer:(void*)baseAddress withBytesPerRow:(NSUInteger)rowBytes pixelFormat:(NSString*)format forBounds:(NSRect)bounds
{
CGContextRef context = CGBitmapContextCreate(baseAddress, bounds.size.width, bounds.size.height,
8, rowBytes, CGImageGetColorSpace(img),
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGImageRef imageRef = CGImageCreateWithImageInRect(img, bounds);
CGContextDrawImage(context, CGRectMake(0, 0, bounds.size.width, bounds.size.height), imageRef);
CGImageRelease(imageRef);
CGContextRelease(context);
return YES;
}