How can I draw the CGImageRef context on the screen?

I have a nice CGImageRef context that I created all day to get alpha values;)

Defined as follows:

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

      

So, for my understanding, this context somehow represents my image. But "practically", invisible somewhere in the memory.

Can I use this in a UIImageView or draw directly to the screen? I am assuming the alpha will be converted to grayscale or something.

+1


a source to share


3 answers


You can create UIImage

by calling:

+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage



and then draw UIImage

using:

- (void)drawAtPoint:(CGPoint)point

+2


a source


Go to CGBitmapContextCreateImage()

which can give you a CGImageRef from your bitmap context. Then you can draw this with CGContext functions ... or create a UIImage with +[UIImage imageWithCGImage:]

.



+2


a source


CGSize size = ...;
UIGraphicsBeginImageContext(size);
...
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
...
CGPoint pt = ...;
[img drawAtPoint:pt];

      

0


a source







All Articles