I don't understand really well the premultiplied alpha.
I need a NSBitmapImageRep without alpha channel (I don't need a particular bpp).
My problem is that this code give me errors:
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];
Error: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component color space; kCGImageAlphaNone; 640 bytes/row.
Okay, I know this combination it's not supported but I need something like this and I don't find a solution.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…