我不太了解预乘的阿尔法。
我需要一个没有 alpha 通道的 NSBitmapImageRep(我不需要特定的 bpp)。
我的问题是这段代码给了我错误:
NSSize imageSize = NSMakeSize(200, 200);
//create a non-alpha RGB image rep with the same dimensions as the image
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
bytesPerRow:(3 * imageSize.width)
bitsPerPixel:24];
//lock focus on the bitmap
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:context];
//draw the image into the bitmap
[prueba drawAtPoint:NSMakePoint(0, 0) withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont systemFontOfSize:24], NSFontAttributeName, nil]];
[NSGraphicsContext restoreGraphicsState];
//get the TIFF data
NSData* tiffData = [bitmap TIFFRepresentation];
//do something with TIFF data
NSError *error = nil;
[tiffData writeToFile:@"/Users/Paul/test.tif" options:NSDataWritingAtomic error:&error];
错误:CGBitmapContextCreate:不支持的参数组合:8 个整数位/分量;24 位/像素;三分量色彩空间;kCGImageAlphaNone; 640 字节/行。
好的,我知道这种组合不受支持,但我需要这样的东西,但我找不到解决方案。