我正在尝试使用如下代码获取位图上下文: ide
GContextRef MyCreateBitmapContext (int pixelsWide, int pixelsHigh) { CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4); // 1 bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);// 2 bitmapData = malloc( bitmapByteCount ); // 3 if (bitmapData == NULL) { fprintf (stderr, "Memory not allocated!"); return NULL; } context = CGBitmapContextCreate (bitmapData, // 4 pixelsWide, pixelsHigh, 8, // bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context== NULL) { free (bitmapData); // 5 fprintf (stderr, "Context not created!"); return NULL; } CGColorSpaceRelease( colorSpace ); // 6 return context; // 7 }
警告说: 'kCGColorSpaceGenericRGB' is deprecated.
spa
这是否意味着colorSpace
更改? 若是是这样,咱们将没法使用colorSpace
更改任何图像的颜色数据。 那么如何处理图像呢? code
不推荐使用通用颜色空间。 相反,尝试; component
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB()
; ip