我正在使用以下代碼來顯示32位灰度圖像。即使我明確設置每個像素爲4294967297(它應該是白色的),但最終結果始終是黑色的。我在這裏做錯了什麼?該圖像只是64x64像素。帶CGBitmapContextCreate的32位灰度圖像始終爲黑色
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
ptr = (float*)malloc(4*xDim*yDim);
for(i=0;i<yDim;i++)
{
for(j=0;j<xDim;j++)
{
ptr[i*xDim + j] = 4294967297;
}
}
CGContextRef bitmapContext = CGBitmapContextCreate(
ptr,
xDim,
yDim,
32,
4*xDim,
colorSpace,
kCGImageAlphaNone | kCGBitmapFloatComponents);
//ptr = CGBitmapContextGetData(bitmapContext);
//NSLog(@"%ld",sizeof(float));
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
NSRect drawRect;
drawRect.origin = NSMakePoint(1.0, 1.0);
drawRect.size.width = 64;
drawRect.size.height = 64;
NSImage *greyscale = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
[greyscale drawInRect:drawRect
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
你見過支持32位浮點灰度的地方嗎?我不是說它不是..只是有興趣 – hooleyhoop 2011-03-29 22:05:21
是的 - 你可以看到支持的像素格式[這裏](http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/ dq_context.html#// apple_ref/DOC/UID/TP30001066-CH203-SW9)。你需要向下滾動一下。 – saad 2011-03-29 23:23:28
是的,看起來你是對的 – hooleyhoop 2011-03-30 08:31:40