Re: How to create CIImage from CGContextRef ?
Re: How to create CIImage from CGContextRef ?
- Subject: Re: How to create CIImage from CGContextRef ?
- From: Scott Thompson <email@hidden>
- Date: Mon, 27 Jun 2005 08:49:18 -0500
On Jun 25, 2005, at 10:00 PM, Pierre CHATEL wrote:
Hi,
is there a way to create a CIImage from a CGContectRef (which is
*not* a bitmap context) ?
I need to create a CIImage from an overlay window.
Here is my code:
CGContextRef overlayContext;
QDBeginCGContext(GetWindowPort(overlayWindow), &overlayContext);
//doesn't work since overlayContext is not a bitmap context !
CGImageRef overlayImage = CGBitmapContextCreateImage(overlayContext);
CIImage *initialCIImage = [[CIImage alloc]
initWithCGImage:overlayImage];
Really, the operation your describing doesn't name much sense. A
CIImage is a set of drawing instructions for creating a graphic. A
CGContext, in contrast, is an environment that you can execute
drawing instructions in.
What it looks like you really want to do is create a CIImage from the
pixels in a graphics port. The way you would do that is create a
CGImage from the pixels of the graphics port, then create a CIImage
from the CGImage. Assuming a 32 bit per pixel CGrafPort, to do that
you would have to do something like the pseudocode (typed into
mail... not verified):
CGrafPort windowPort = GetWindowPort(overlayWindow);
LockPortBits(windowPort);
PixMapHandle thePixels = GetPortPixMap(windowPort);
LockPixels(thePixels );
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateWithName
(kCGColorSpaceGenericRGB);
CGDataProvider dataProvider = CGDataProviderCreateWithData(NULL,
GetPixBaseAddr(thePixels), height * GetPixRowBytes(thePixels), NULL);
CGImageRef cgImage = CGImageCreate(width, height, 8, 32,
GetPixRowBytes(thePixels), rgbColorSpace, kCGImageAlphaNoneSkipFirst,
dataProvider, NULL, true, kCGRenderingIntentDefault);
CFRelease(dataProvider);
CFRelease(rgbColorSpace);
CIImage *coreImageImage = [[CIImage alloc] initWithCGImage: cgImage];
CFRelease(cgImage)
/* use CIImage here */
[coreImageImage release];
UnlockPixels (thePixels);
UnlockPortBits(windowPort);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden