views:

1482

answers:

3

I have a beautiful CGImageRef context, which I created the whole day to get alpha values ;)

It's defined like that:

CGContextRef context = CGBitmapContextCreate (bitmapData, pixWidth, pixHeiht 8, pixWidth, NULL, kCGImageAlphaOnly);

So for my understanding, that context represents somehow my image. But "virtually", non-visible somewhere in memory.

Can I stuff that in an UIImageView or draw that directly to the screen? I guess that alpha would be converted to grayscale or something like that.

+1  A: 

You can create a UIImage by calling:

+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage

and then draw the UIImage using:

- (void)drawAtPoint:(CGPoint)point

pgb
A: 
CGSize size = ...;
UIGraphicsBeginImageContext(size);
...
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
...
CGPoint pt = ...;
[img drawAtPoint:pt];
Ed Marty
+1  A: 

Go look at CGBitmapContextCreateImage(), that can give you a CGImageRef from your bitmap context. You can then draw that using the CGContext... functions or make a UIImage using +[UIImage imageWithCGImage:].

Kevin Ballard