I am trying to compile the function pasted below. I copied it from "Quartz 2D Primer" or somesuch, as it does exactly what I think I need.
( And when I say, "copied", I mean I had to type to whole thing myself, as the text was not 'selectable' in the PDF. Heh. Thx, Apple )
So I'd like to just compile this one file. It contains references to "CGDataProvider" etc, which are undefined without appropriate includes.
Ok, fine. I loate the file which defines "CGDataProvider", and attempt to include it:
#import <CGDataProvider.h>
But that doesn't work. Fine. So I try:
#import <CoreGraphics/CGDataProvider.h>
But that doesn't work. Fine. So I try:
#import <CoreGraphics/CoreGraphics.h>
But that doesn't work.
*Excuse me*, but what the heck is going on with this new goofy magic with "import" and the whole slash thing? I know exactly which file contains the definition, but I can't include it... Where is this goofiness documented?? Aaaargh/Thx.
( And when I say, "copied", I mean I had to type to whole thing myself, as the text was not 'selectable' in the PDF. Heh. Thx, Apple )
So I'd like to just compile this one file. It contains references to "CGDataProvider" etc, which are undefined without appropriate includes.
Ok, fine. I loate the file which defines "CGDataProvider", and attempt to include it:
#import <CGDataProvider.h>
But that doesn't work. Fine. So I try:
#import <CoreGraphics/CGDataProvider.h>
But that doesn't work. Fine. So I try:
#import <CoreGraphics/CoreGraphics.h>
But that doesn't work.
*Excuse me*, but what the heck is going on with this new goofy magic with "import" and the whole slash thing? I know exactly which file contains the definition, but I can't include it... Where is this goofiness documented?? Aaaargh/Thx.
Code:
// iWidth width of bitmap
// iHeight height of bitmap
// iBytesPerRow number of bytes per row, given by GetPixRowBytes()
// contextR a Core Graphics context to draw the image to
void Draw32BitARGBToContext( void* iBitsP, size_t iWidth, size_t iHeight, size_t iBytesPerRow, CGContextRef contextR ) {
CGRect rectangle;
CGDataProvider provider;
CGColorSpaceRef colorSpace;
size_t size;
CGImageRef image;
size = iBytesPerRow * height;
// Create a data provider with a pointer to the memory bits
provider = CGDataProviderCreateWithData( NULL, iBitsP, size, NULL );
// Colorspace can be device, calibrated, or ICC profile based
colorSpace = CGColorSpaceCreateDeviceRGB();
// Create the image
image = CGImageCreate( iWidth, iHeight,
8, // bitsPerComponent
32, // bitsPerPixel
iBytesPerRow, colorSpace, kCGImageAlphaFirst, provider, NULL, 0, kVGRenderingIntentDefault );
// Once the image is created we can release our reference to the provider and the colorspace.
// They will be retained by the image.
CGDataProviderRelease( provider );
CGColorSpaceRelease( colorSpace );
// Determine the location where the image will be drawn in userspace.
rectangle = CGRectMake( 0, 0, iWidth, iHeight );
// Draw the image to the Core Graphics context
CGContextDrawImage( context, rectangle, image );
CGImageRelease( image );
}