![](/img/trans.png)
[英]iOS OpenGL ES 2.0: Offscreen render and save the result to an UIImage
[英]How to render offscreen IOS
我正在尝试快速实施metaball,但在途中遇到了这个问题。 基本上,我需要在屏幕外绘制一些Alpha径向渐变,然后检查每个像素值是否高于某个Alpha阈值,而不是像素变为黑色,否则变为白色。
问题是我无法弄清楚如何制作可以在其上绘制并进行计算然后在屏幕上显示它的屏幕外上下文。
我进行了无休止的搜索,但对UIcontexts和CGContext之间的差异感到非常困惑。 在当前尝试中,我使用CGBitmapContext,但无济于事。 任何帮助将不胜感激(最好是迅速,但一切都会发生)。
您可以按此处所述绘制位图图形上下文。
这是创建图像上下文,使用CG调用绘制到上下文,然后获取UIImage的方法:
// Create an N*N image
CGSize size = CGSizeMake(N, N);
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// EG:
CGColorRef backColor = [UIColor lightGrayColor].CGColor;
CGContextSetFillColorWithColor(ctx, backColor);
CGContextFillRect(ctx, r1);
.... more drawing code
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
您可以很容易地获得CGImageRef:
CGImageRef cgImage = image.CGImage;
最后,你可以得到底层字节解释这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.